[英]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.