简体   繁体   English

移动Safari禁用iOS 5中的Ajax功能

[英]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. 我有一个运行在jQuery Mobile / PhoneGap上的移动应用程序,在iOS 5中,只有一段时间后我的ajax回调停止触发。 I'm using jQuery's $.ajax function, and here are some of the error messages I've got: 我正在使用jQuery的$.ajax函数,这是我收到的一些错误消息:

  • textStatus = parsererror textStatus = parsererror
  • errorThrown = undefined was not called errorThrown =未定义未调用

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? 我的问题是,如果抛出太多错误,Mobile Safari是否会在一段时间后禁用功能?

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. 我对发生的事情的猜测是,当移动设备的连接速度太慢时,我抓取的JSON文件(214K)使AJAX调用的持续时间太长(> 10s?),并且Mobile Safari取消了AJAX调用。 Then, after X number of cancelled AJAX calls, it seems like Mobile Safari disables the callback function completely. 然后,在X次取消的AJAX调用之后,Mobile Safari似乎完全禁用了回调功能。

Anyone else with similar behavior? 其他人有类似的行为吗?

I use $.ajax often and have not experienced this problem. 我经常使用$ .ajax,并且没有遇到此问题。 I suggest setting timeout to 50000 for a slow connection. 我建议将超时设置为50000以使连接缓慢。 To see the error, somewhere in your html add: 要查看错误,请在您的html中添加:

 <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 + ")");
    },
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM