2011-04-04 22 views
2

我的要求是,我在我的項目中寫了很多$ .post方法。 我想檢查每個請求中的會話,並根據會話值, 我想處理我的頁面。但我不想修改會話的所有方法($。post), 因此,我想檢查會話在「ajaxStart或ajaxSend」並取決於 我想中止主要AJAX調用的響應。如何中止ajaxStart或ajaxSend中的AJAX請求?

我試圖用我下面的示例代碼的小knowledge.The不工作,因爲 $。員額是asynchronous.Could任何一個可以幫助我在ajaxStart或ajaxSend狀態中止一個Ajax請求 ?

var pp; 
link=function(id){ 
var url="http://localhost/jqueryui/test.php"; 
    pp=$.post(url,{"id":id},function(data){ 
     $("#div"+id).html(data); 
    }); 
} 
$(function(){ 
    $("#loading").ajaxStart(function(){ 
     alert("Hi start"); 
     $(this).show(); 
       var url="http://localhost/jqueryui/test.php"; 
      $.post(url,{"id":99},function(data){//checking the session 
      if(data == "close") 
      pp.abort();   
      }); 
    }); 
}); 
+0

@corroded:我同意,你有什麼建議。但我必須對我的代碼做更多的更改。因爲這個原因,我正在尋找一些替代解決方案。 – Priyabrata 2011-04-04 13:24:31

+0

我確實認爲這比嘗試用中止Ajax調用破解你的方式更可行。這是對Ajax電話的浪費。 – corroded 2011-04-04 13:39:49

+0

[在ajaxStart中停止jquery ajax請求]的可能重複(http://stackoverflow.com/questions/11788011/stop-jquery-ajax-request-in-ajaxstart) – Barun 2013-11-08 09:54:25

回答