[英]How can i stop ajax request and then continue?
如何停止 Ajax 请求然后继续,例如,如果状态代码响应为403
,则停止此请求并提示用户是否要继续。
$.ajax({
url: t,
method: "GET",
async: true,
xhrFields: {
withCredentials: true
},
success: function(data, textStatus, xhr) {
if (xhr.status == 403) {
//how can i stop this request call prompt if click ok then
var check = prompt("Do you want this request?");
if (check) {
//success code
}
}
}
}); //ajax
用
$.ajax( ...params... )
.then(
function(data, textStatus, jqXHR) {
alert("Success: " + data);
// initiate next sequential operation
},
function(jqXHR, textStatus, errorThrown) {
alert("Error: " + errorThrown);
// initiate next sequential operation
});
回答
function requestT(t){
$.ajax({
url:t,
method:"GET",
async: true,
xhrFields: {
withCredentials: true
}
}).then(function(data,textstatus,xhr) {
//your code....
},
function(xhr,text,error){
var x = prompt("do you want to continue if YES enter 1?");
if(x == 1){
console.log("reload Request...");
requestT(t);
}
}
);//ajax
}//func request
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.