2017-07-19 57 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();

相關問題