iOS 7 javascript XMLHttpRequest错误 [英] iOS 7 javascript XMLHttpRequest bug

查看:814
本文介绍了iOS 7 javascript XMLHttpRequest错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章是半个问题 - 半个公告..我开发iOS应用程序,其中包括执行javascript代码的UIWebView。
当我在使用新iOS 7的设备上运行应用程序时,某些功能无效。经过长时间调试后
,我已设法找出原因。
Javascript AJAX有一个请求API,构造函数方法打开:

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)

XMLHttpRequest.open(method,url,async)

如果调用应该是阻塞,则asynch'参数为false,否则为true。
问题仅限iOS 7 safari ,如果'async'为false,此方法会抛出异常。

'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

谢谢!

推荐答案

UIWebview不允许IOS7中的同步XHR。

The UIWebview does not allow synchronous XHRs in IOS7.

这是WebView和Safari之间令人沮丧的差异之一(允许它们)。

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

解决方法:


  1. 创建一个Objective-C函数,该函数生成同步HTTP请求

从JavaScript调用该功能。 (这是同步发生的。)

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

当然,如果你想要任何好处,比如缓存,你必须实现自己。

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

为什么Apple认为要求解决方法是一个好主意,这有点令人费解。

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

这篇关于iOS 7 javascript XMLHttpRequest错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆