[英]Set variable value if jQuery AJAX request is error
I'm working on a form that has 4 different ajax request and I want to check if all 4 are successful. 我正在处理具有4个不同的ajax请求的表单,我想检查所有4个是否都成功。 If they all are successful I want to switch step. 如果它们都成功,我想切换步骤。
Im trying something like this: If i get error on one of the request i want to change the "ss" variable to false. 我正在尝试这样的事情:如果我在请求之一上遇到错误,我想将“ ss”变量更改为false。
var ss;
ss = true;
if (ss === true) {
this.owner.switchStep(3);
};
$.ajax({
url: url,
type: method,
data: JSON.stringify(estate),
beforeSend: function() {},
success: function(response) {},
error: function(xhr, thrownError, code) {
return ss = false;
},
complete: function() {}
});
$.ajax({
...
error: function(xhr, thrownError, code) {
return ss = false;
},
...
});
$.ajax({
...
error: function(xhr, thrownError, code) {
return ss = false;
},
...
});
$.ajax({
...
error: function(xhr, thrownError, code) {
return ss = false;
},
...
});
Chain your requests or put them synchronous (setting is async: false
). 链接您的请求或使其同步(设置为async: false
)。
Btw are you sure to need 4 ajax requests ? 顺便说一句,您确定需要4个Ajax请求吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.