iOS 7 javascript XMLHttpRequest bug - Stack Overflow

This post is half question - half announcement..i develop iOS applications which include UIWebView th

This post is half question - half announcement.. i develop iOS applications which include UIWebView that performs javascript code. When i run the app on devices with the newly iOS 7, some of the functionality doesn't work. after long debugging, i have managed to isolate the reason. Javascript AJAX has a request API with the constructor method open :

XMLHttpRequest.open(method,url,async)

'asynch' argument is false if the call should be blocking and true otherwise. the problem on iOS 7 safari only is that this method throws exception if 'async' is false.

so, hope this would help to any of you encountering the same problem, and if anyone can shad a light about this bug or way to work around it it would be great

Thanks!

This post is half question - half announcement.. i develop iOS applications which include UIWebView that performs javascript code. When i run the app on devices with the newly iOS 7, some of the functionality doesn't work. after long debugging, i have managed to isolate the reason. Javascript AJAX has a request API with the constructor method open :

XMLHttpRequest.open(method,url,async)

'asynch' argument is false if the call should be blocking and true otherwise. the problem on iOS 7 safari only is that this method throws exception if 'async' is false.

so, hope this would help to any of you encountering the same problem, and if anyone can shad a light about this bug or way to work around it it would be great

Thanks!

Share edited Sep 23, 2013 at 22:43 Eliktz asked Sep 23, 2013 at 17:29 EliktzEliktz 5721 gold badge6 silver badges27 bronze badges 2
  • I believe they pulled the ability to make synchronous calls awhile back. – epascarello Commented Sep 23, 2013 at 18:43
  • Don't. You should avoid synchronous http requests as much as possible. What if the user is on a super-slow network and your request locks the application for 4-8 seconds? – fregante Commented May 27, 2014 at 13:20
Add a ment  | 

1 Answer 1

Reset to default 6

The UIWebview does not allow synchronous XHRs in IOS7.

This is one of the frustrating differences between the WebView and Safari (which does allow them).

The workaround:

  1. Create an Objective-C function that makes a synchronous HTTP request.

  2. Call that function from JavaScript. (This happens synchronously.)

Of course, if you wanted any benefits like caching, you would have to implement that yourself.

It's a bit baffling why Apple would think requiring that workaround is a good idea.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745060452a4608935.html

相关推荐

  • iOS 7 javascript XMLHttpRequest bug - Stack Overflow

    This post is half question - half announcement..i develop iOS applications which include UIWebView th

    19小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信