gpt4 book ai didi

javascript - 从1.3.2升级到1.8.3时jquery ajax成功

转载 作者:行者123 更新时间:2023-11-28 09:27:19 25 4
gpt4 key购买 nike

我有一个问题:)

我将旧的 jquery 1.3.2 升级到最新版本 1.8.3。

当然,从这样的旧版本升级会导致我的自定义 jquery 代码出现问题:)

我发现我应该使用代理而不是绑定(bind),但我的 ajax 代码仍然有问题。

我不是一个经验丰富的 JavaScript 调试器,但对我来说,ajax 成功似乎不会触发 setProgress 中的 Google Chrome 断点。

我的代码:

getProgress: function() {
$.ajax({type: "GET", url: "/progress", dataType: "json",
beforeSend: $.proxy(function(xhr) {
xhr.setRequestHeader("X-Progress-ID", this.uuid);
}, this),
success: $.proxy(this.setProgress, this)
});
},
setProgress: function(data) {
if (data.state == "done") {
this.finished();
} else if (data.state == "error") {
alert("ERROR"+data.status);
this.finished();
} else if (data.state == "starting") {
this.statusText.text("Startar");
this.setTime();
} else {
bps = bytesPerSecond((new Date()).getTime()-this.lastTime, this.received, data.received);
this.lastTime = (new Date()).getTime()
try { remaining = (this.size-this.received)/bps; } catch(err) { remaining = 0; }
this.received = data.received;
this.size = data.size;
this.statusText.html(
(this.received/this.size).toPercentage()+
" Uppladdat ( "+
data.received.toHumanSize()+
" av "+
data.size.toHumanSize()+
" )   "+
bps.toHumanSize()+
"/s   "+
timeLeft(remaining)+
" kvar"
);
this.statusText.width((this.progressBar.width()-40)*(this.received/this.size)+20);
this.setTime();
}
},

我猜想 jquery 1.4+ 中对 ajax 进行了一些更改,这破坏了我的代码。有什么想法可能是错误的吗?

最佳答案

好的,我找到了解决方案:)

这并不是真正导致问题的代码。这是我的 Nginx conf 没有输出纯 json,jquery 现在在 1.4+ 版本中验证(这就是它在 jquery 1.3.2 中工作而不是在较新版本中工作的原因)。

所以我将其添加到我的 Nginx 配置中:

location ^~ /progress {
upload_progress_json_output;
report_uploads proxied;
}

关于javascript - 从1.3.2升级到1.8.3时jquery ajax成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14181900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com