2017-07-19 58 views
0

我正在使用多个ajax调用。但使用AjaxSetUp知道是否允许呼叫,如果不​​是,则尝试在beforeSend方法中放弃此操作。如何在发送ajaxsetup的方法之前中止父ajax调用

这里是Ajax调用

     $.ajax({ 
          type : "POST", 
          url : "/apps/doAction", 
          xhrFields : "checkIfAllowed", 
          success : function(response,xhr) { 
          if(response){ 
           return false; 
          } 
          }, 
          error : function(xhr,ajaxOptions,thrownError) { 
          } 
         }); 

这里是AjaxSetUp

$.ajaxSetup({ 
      beforeSend: function(event, xhr, settings) { 
       event.xhrToAbort=xhr; 
       if(xhr.xhrFields == "checkIfAllowed"){ 
        $.ajax({ 
          type : "POST", 
          url : contextpath+ "/apps/auth/isAllowed", 
          success : function(response,xhr) { 
          if(response){ 
          // ABORT PARENT CALL ("URL: /apps/doAction") unable to abort parent call.. 
          } 
          }, 
          error : function(xhr,ajaxOptions,thrownError) { 
          } 
         }); 
       } 
      }, 
      complete: function(event, xhr, settings) { 
       $('.trans-overlay').hide(); 
      } 
     }); 

回答

0

通过更换event.xhrToAbort=xhr;event.xhrToAbort=event; 并要放弃使用像event.xhrToAbort.abort();

相关问题