gpt4 book ai didi

jquery - 如何在成功回调时触发ajax错误回调?

转载 作者:行者123 更新时间:2023-12-03 22:47:52 27 4
gpt4 key购买 nike

我正在寻找一种在成功回调中触发ajax错误的方法。我试图在下面解释我的问题代码:

$.ajax({
url: requestURL,
data: postData,
type: 'post',
success: function(response){
if(response.Success){
// do something
}else{
// request workflow fails in this case,
// i have to trigger this ajax request's error callback
}
},
error: function(){
// do something on error case
},
dataType: 'json'
});

最佳答案

var errorhandler = function(xhr, textStatus, error){
// do something on error case
};

$.ajax({
url: requestURL,
data: postData,
type: 'post',
success: function(response){
if(response.Success){
// do something
}else{
errorhandler();
}
},
error: errorhandler,
dataType: 'json'
});

关于jquery - 如何在成功回调时触发ajax错误回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3609540/

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