JQuery AJAX 功能在 iOS 5 Safari/iPad 中不起作用
在 iPad 上的 iOS 5 safari 上使用最新版本的 jQuery 1.6,我注意到所有的 ajax 调用都失败了。这些相同的 ajax 调用在我尝试过的所有其他浏览器上都能按预期工作,而且我很确定它们也在 iOS 4 版本的 Safari 上工作(尽管我可能是错的)。还有其他人也经历过这种行为吗?如果是这样,有修复或解决方法吗?下面是一个简单的 jQuery AJAX 调用的快速示例,该调用在 iOS 5 的 Safari 中返回错误。预先感谢您的任何见解!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
</head>
<body>
<a id="my-link" href="javascript:;">Click Me!</a>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#my-link").bind("click", function() {
jQuery.get("test.php", function(data) {
alert(data);
});
});
});
</script>
</body>
</html>
Using the latest version of jQuery 1.6 on iOS 5 safari from an iPad, I'm noticing that all my ajax calls are failing. These same ajax calls work as expected on all other browsers I've tried, and I'm pretty sure they were also working on iOS 4's version of Safari (although I could be wrong). Has anyone else experienced this behavior as well? If so, is there a fix or workaround? Below is a quick example of a simple jQuery AJAX call that is returning an error in iOS 5's Safari. Thanks in advance for any insight!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
</head>
<body>
<a id="my-link" href="javascript:;">Click Me!</a>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery("#my-link").bind("click", function() {
jQuery.get("test.php", function(data) {
alert(data);
});
});
});
</script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我刚才也有类似的问题。我已将
url: 'http://IP../ws' 更改为 url: 'ws',
我根本不是 jQuery 用户,但必须将它用于项目,所以不确定这是否对您有帮助或不,但为我工作。
I had a similar issue just now. I had
changed url: 'http://IP../ws', to url: 'ws',
I'm not a jQuery user at all but have to use it for a project so not sure if this is help to you or not but worked for me.
重新启动 Safari - 保留它并从正在运行的任务中终止它。
从我读到的其他内容来看,它与安全上下文和跨站点脚本攻击的预防有关,并且当 Safari 以前在不同的网络上运行并且现在在新网络上运行且在更改之间没有停止时,Safari 并没有完全正确地处理事情网络。
今天我自己遇到了这个问题,使用纯 HTML/JavaScript/PHP XMLHttpRequest 请求。
Restart Safari - leave it and kill it from the running tasks.
From other things I have read it is related to security contexts and prevention of cross site scripting attacks, and Safari not getting things quite right when it was previously running on a different network and is now on an new network without it having been stopped between changing networks.
Ran into it myself today, w/ plain HTML/JavaScript/PHP XMLHttpRequest request.
我遇到一个问题,即 Safari 浏览器中的 iPad 中的 jQuery ajax 调用失败。错误是您没有权限访问该页面/目录。我通过将 Ajax async 属性更改为 true 来解决该问题。
I had face one issue that jQuery ajax call fail in IPad in Safari browser. Error is you have no permission to access the page / directory. I fix the issue by changing the Ajax async property to true.
Safari Mobile 中存在一个错误,如果正在进行任何文件服务,该错误会突然且意外地给 AJAX 调用带来麻烦。在使用
Content-Disposition:attachment;
标头提供下载后,Safari 可以开始发送“OPTIONS”http 消息而不是 POST。您可以通过在 Safari Mobile 和服务器之间使用 Fiddler 查看 Safari 正在发送哪些 HTTP 消息来查看是否发生这种情况。Safari Mobile 中的“条件”会在重新启动时重置。
这里对其进行了很好的审查 Stackoverflow:JQuery Ajax 停止使用iOS 5.0.1。
There is a bug in Safari Mobile that suddenly and unexpectedly gives troubles with AJAX calls if there is any file serving going on. Safari can starts sending "OPTIONS" http messages rather than POST after it has been served a download with a
Content-Disposition: attachment;
header. You can look to see if this is happening by using Fiddler between Safari Mobile and the server to see what HTTP messages Safari is sending.That "condition" in Safari Mobile is reset when restarted.
It is reviewed well here Stackoverflow: JQuery Ajax stopped working with IOS 5.0.1.
我必须让它在出现错误时重试最多 20 次才能使其正常工作。代码示例:
I've had to make it so that it re-try up to 20 times on error to make it work. Code example:
我遇到了同样的问题,但最终发现了完全不同的东西。
我的情况是这样的:
之后我
在 Chrome、Firefox、OSX 版 Safari、iPhone 版 Safari、iPhone 版 Chrome 中一切正常,但在 Edge 和 iPad 版 Safari 上一切都不起作用。因此,我在 Edge 上打开它,在开发人员工具中,它在定义
load_one
函数的行上显示错误。我不确定这是什么,但错误说
)预期
,所以我决定删除函数参数的默认值,一切突然都正常了。我不确定 javascript 是否存在默认参数值问题,但显然某些浏览器存在问题。I had the same issue but I ended up discovering something different totally.
I had something like:
And after that I had
Everything worked fine in Chrome, Firefox, Safari for OSX, Safari for iPhone, Chrome for iPhone, but on Edge and Safari for iPad nothing worked. So I opened it on Edge and inside the developer tools it was showing an error on the line where the
load_one
function was defined.I wasn't sure what it was but the error said
) expected
so I decided to remove the default values for the function parameters and everything worked all of a sudden. I am not sure if javascript has issues with default parameter values, but apparently some browsers have issues with that.