总计ajax请求的数量,并在它是最后一个ajax响应时显示ajax响应。
换句话说,如何仅使用上次发送的ajax请求的响应。
var req=0;
function ajaxReq(){
req++; /total up the amount of request/
$.ajax({
url: "result.php",
type: 'GET',
contentType: false,
enctype: 'multipart/form-data',
cache: false,
processData: false,
success: function(response) {
if(req==1){ /show the response when this is the last request/
$("#response-element").html(response);
}
req--; /Subtract when every success ajax response/
}
});
}
如果用户在响应显示之前单击了几个线程,我将在查看消息详细信息时使用它,它将在显示当前选定的线程详细信息之前显示先前的线程详细信息
任何更好的解决方案都适合共享
您应该在发送请求后立即递减。
var req=""; // should be a number
function ajaxReq(){
req++; /total up the amount of request/
$.ajax({
url: "result.php",
type: 'GET',
contentType: false,
enctype: 'multipart/form-data',
cache: false,
processData: false,
beforeSend: function() {
if (req > 1) req -= 1;
},
success: function(response) {
if(req==1){ /show the response when this is the last request/
$("#response-element").html(response);
req -= 1;
}
}
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句