开发者

AJAX status code not the same as Chrome network console status code

All content is loaded into my page using JQuery/AJAX calls to some CakePHP functions and dumping the response HTML into a container DIV.

Often the page contains a form that I would like to POST prior to injecting the new page into the container DIV. This POST is done when the user hits the home page button.

The form data is sent via POST to a CakePHP function which then saves the data and echo's a "save complete" message before die(). then the home page is loaded into the container div after calling my post function.

The problem is, sometimes it doesn't always save my form data.

There are 2 scenarios:

1 - save works. response code is 200. response data is "save complete"

2 - save does not work. the response code (according to my js function) is 200 because I alert it. However, in this situation Chrome says the response is 302. and the response data contains my home page. my cakephp code has NO redirects in the function I am POSTing to.

my home page button:

function aj开发者_StackOverflow社区axLoad(url) {

    saveThisPage();


    $.ajaxSetup ({// Disable caching of AJAX responses      
        cache: false
    });

    $('#content').load(url, function(response, status, xhr));

    return false;
}

saveThisPage =function() {
    var roc_data = $("#CustomerRocForm").serialize()
    var roc_url = '/customers/roc'

    $.ajaxSetup ({      
        cache: false
    });

    $.post(roc_url, roc_data, function(roc_response, roc_status, roc_xhr) { 
        alert(roc_xhr.status)
    });
}

tl;dr:

user hits home page button. this posts form on current page, then loads home page into container div. form submission POST sometimes returns 302


I added this parameter to saveThisPage() and it seems to be working for now. I would prefer the POST to be async because it slows down the page loads while waiting for the response, but at least its working.

$.ajaxSetup ({      
    cache: false,
    async: false
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜