I use jQuery's ajax method to make jsonp requests to my server (I make a request every now and then). This usually works just fine, the server returns a response and my "success" callback function is triggered.
Problem is, after a while, the success function stops being called, even though I receive a successful response from t开发者_如何学运维he server. When this happens, every successive jsonp request also "fails" (even from other places in the code and\or to other paths on my server).
Things I've checked:
The response from the server is valid (the same as other successful responses).
The jsonpXXX callback function that jQuery creates, is indeed globally defined.
When I open multiple browsers on the same page, it doesn't happen in all of them.
My client side code is:
$.ajax({
type: "GET",
url: SOME_URL,
dataType: "jsonp",
data: {...},
success: function(data) {
alert("This function is not always being called :( ");
}
});
Any ideas\help will be greatly appreciated :)
You may receive a successful response from the server, but there may be some issues with the returned JSONP text. If there are any errors parsing the response, calling the callback function will fail.
Also, I suggest using this alternative solution to jQuery's implementation of JSONP which simplifies JSONP requests.
精彩评论