Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

javascript - jquery AJAX stopped working with iOS 5.0.1

The following piece of logic used to work with both jquery 1.4.4 and 1.7.1 on all mobile devices that we're supporting:

$.ajax({
  url: 'http://www.example.com/someurl',
  type: 'GET',
  dataType: 'text',
  timeout: 60000,
  success: function(data) {
    alert(data);
  },
  error: function(jqXHR) {
    alert(jqXHR.state());
  }
});

But with iOS 5.0.1, the above enters the error function alerting rejected without any actual HTTP requests. It seems that exactly one AJAX request will work before I need to restart my iPhone. Is this a known jquery / iOS 5.0 problem? How can I debug it? Is there any workaround? I don't know where to start looking.

NOTE: I've noticed on the server side, that instead of GET requests, OPTIONS requests are issued. This seems to be a related issue:

http://spin.atomicobject.com/2012/01/20/mobile-safari-on-ios-5-1-unexpectedly-making-cross-origin-resource-sharing-requests/

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The link that I provided in the question is actually pointing to the solution. Some of my ajax requests are used to fetch URL's of PDFs which are streamed using

Content-Disposition: attachment; filename="somename.pdf"

Apparently, that causes major issues in iOS 5.0's Safari, breaking the XMLHttpRequest object (it is not related with jquery). Crazy. Here's the link again:

http://spin.atomicobject.com/2012/01/20/mobile-safari-on-ios-5-1-unexpectedly-making-cross-origin-resource-sharing-requests/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...