仅在通过ajax全局事件的POST请求上显示div



我有ajax全局事件来显示覆盖在每个ajax点击文档,它看起来像:

$(document).ajaxSend(function (e, jqXHR) {
    //show the loading div here
    $('#DivProgressBar').show(); //if ajax is Post only 
});
$(document).ajaxComplete(function (e, jqXHR) {
    //remove the div here
    $('#DivProgressBar').hide(); //if ajax is Post only 
});

现在我想这个覆盖应该只适用于post请求,而不是get请求。我可以修改我当前的jquery代码来实现这一点吗?

谢谢。

$(document).ajaxSetup({type: 'POST'});只能用于post request

jQuery(element).ajaxComplete(function(event, request, settings) {
    alert(settings.type);
});

发现在这个答案中:https://stackoverflow.com/a/6710284/643761

最新更新