用于进度条的 $.getJSON 在 Safari 和 Chrome 中不起作用(但在 IE6+ 和 FF 中正常)

发布于 2024-09-10 04:36:27 字数 537 浏览 5 评论 0原文

这也许有点啰嗦,但它确实让我和其他几个人感到困惑。

我们有一个在文件上传期间更新的进度条。 JS 位于此处(太多,无法粘贴到此正文中)。

基本上,表单提交事件启动一个计时器循环,每 2 秒向服务器触发 $.getJSON() 调用,以检索有关上传状态的一对值。然后这些值被传递给更新进度条的函数。返回的 JSON 值是有效的 JSON。

现在,这段代码在 Firefox 和所有 IE(甚至 6 个)上都可以正常工作,所以我非常有信心服务器端代码是健壮的,但是......在 Safari 和 Chrome 中,进度条根本不更新。

上传由 Apache 处理得很好,console.log() 调试显示计时器循环肯定在运行——只是 getJSON 似乎没有被触发(Web 检查器没有显示调用,Apache 也没有显示)如前所述

,有人在使用 Chrome/Safari/Webkit 时遇到过这个问题吗?

This one's perhaps a little long-winded, but it's really baffling me and a couple of other people.

We've got a progress bar that's updated during file uploads. The JS is here (too much to paste into this body).

Basically, the form submit event starts a timer loop which, every 2 secs, fires a $.getJSON() call to the server to retrieve a pair of values about the status of the upload. These values are then passed to a function that updates the progress bar. The JSON values returned are def valid JSON.

Now, this code works fine on Firefox and all IEs (even 6), so I'm pretty confident that the server-side code is robust, but... in Safari and Chrome, the progress bar just doesn't update at all.

The upload is processed by Apache fine, and console.log() debugging shows that the timer loop is definitely running -- it's just that getJSON seems not to be firing (the web inspectors don't show the call, and neither does the Apache log.

As said, it's a bit baffling. Anyone come across this before with Chrome/Safari/Webkit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幸福%小乖 2024-09-17 04:36:27

也许这个问题可以提供一些有关调试的想法。我发现 Safari 和 Chrome 在处理 JS 的方式上也存在一些问题,所以,你绝对不是唯一这样的人。

Perhaps this question can provide a few ideas about debugging. I have found both Safari and Chrome to be somewhat buggy with the way they handle JS as well, so, you're definitely not alone.

做个少女永远怀春 2024-09-17 04:36:27

看来 Chrome 的 JSON.parse barfs 对转义的撇号:

[ "barf\'" ]

而未转义的撇号工作正常:

[ "accept'" ]

我已经能够通过为基于 Webkit 的浏览器保留撇号不加引号来规避类似的问题。您的情况可能与此类似。

It seems that Chrome's JSON.parse barfs on escaped apostrophe:

[ "barf\'" ]

while unescaped apostrophe works fine:

[ "accept'" ]

I have been able to circumvent similar problem by leaving the apostrophe unquoted for Webkit based browsers. It might be something similar in your case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文