且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在完成前一个请求之前中止新的 AJAX 请求

更新时间:2023-11-28 15:40:46

 var currentRequest = null;    

currentRequest = jQuery.ajax({
    type: 'POST',
    data: 'value=' + text,
    url: 'AJAX_URL',
    beforeSend : function()    {           
        if(currentRequest != null) {
            currentRequest.abort();
        }
    },
    success: function(data) {
        // Success
    },
    error:function(e){
      // Error
    }
});