gpt4 book ai didi

jquery - 如何在 Jquery 3.x 中为 $.post 添加超时

转载 作者:行者123 更新时间:2023-12-01 00:13:36 25 4
gpt4 key购买 nike

$.post("result.php", {
name: vname,
email: vemail
}, function(response, status){
// Required Callback Function
});

我有这段代码,我只想添加 10 秒的超时,如果用户网络出现故障,我应该提醒“检查您的互联网连接”。我不想使用 $.ajax

最佳答案

您可以使用完整的 $.ajax() 调用并提供 timeout 属性:

$.ajax({
url: 'result.php',
timeout: 10000,
data: {
name: vname,
email: vemail
},
success: function(response) {
// Required Callback Function
}
});

或者,您可以使用 $.ajaxSetup() 来影响当前范围内的所有 AJAX 调用:

$.ajaxSetup({
timeout: 10000
});
$.post("result.php", { name: vname, email: vemail }, function(response, status) {
// Required Callback Function
});

关于jquery - 如何在 Jquery 3.x 中为 $.post 添加超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40396799/

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