iOS 7 javascript XMLHttpRequest bug

不羁岁月 提交于 2019-12-21 02:45:27

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/18965329/ios-7-javascript-xmlhttprequest-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!