gpt4 book ai didi

javascript - jQuery 处理 Ajax 超时?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:28:52 25 4
gpt4 key购买 nike

我正在尝试使用 jQuery 1.4.2 捕获 Ajax 超时错误,但我发现没有一个教程有效。在 Firebug 中,当超时错误触发时。我明白了:

uncaught exception: [object Object].

请帮我处理 Ajax 超时。这是我的 JS 代码:

$.ajax({
type:"POST",
url:"/data/add/",
data:
{
"date":$("input#date").val();
},
dataType:"json",
timeout:2000,
success: function(response) {
},
error: function () {
alert('Server error');
}
});

最佳答案

我对此进行了测试,如果您从 $("input#date").val() 语句中删除 ;,它应该可以工作。

$.ajax({
type:"POST",
url:"/data/add/",
data:
{
"date":$("input#date").val()
},
dataType:"json",
timeout:2000,
success: function(response) {
},
error: function () {
alert('Server error');
}
});

关于javascript - jQuery 处理 Ajax 超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3539895/

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