Mobile Safari disables ajax function in iOS 5
I have a mobile app running on jQuery Mobile/PhoneGap, and in iOS 5-only my ajax callback stops firing after a while. I'm using jQuery's $.ajax
function, and here are some of the error messages I've got:
In the second error above 'undefined' is my callback function. My question is, does Mobile Safari disable functions after a while if too many errors are thrown?
My guess as to what's occurring is that when a mobile device's connection is too slow, the JSON file I'm grabbing (214K) makes the AJAX call last too long (> 10s?), and Mobile Safari cancels the AJAX call. Then, after X number of cancelled AJAX calls, it seems like Mobile Safari disables the callback function completely.
Anyone else with similar behavior?
I use $.ajax often and have not experienced this problem. I suggest setting timeout to 50000 for a slow connection. To see the error, somewhere in your html add:
<div id='text1'>No Error yet...</div>
and timeout parameter would be added similar to:
$.ajax({
type: "GET",
url: "yourpage.html",
async: true,
cache: false,
timeout:5000,
success: function(data){
//something with the data
},
error: function(XMLHttpRequest, textStatus, errorThrown){
$("#text1").text("Comet Timeout ERROR: " + textStatus + " (" + errorThrown + ")");
},
});
链接地址: http://www.djcxy.com/p/55690.html
上一篇: 在asp.net中缓存