2011-08-24 77 views
2

嗨我送通過Ajax請求,我想處理的東西時,Ajax請求發送如何在ajax請求發送時執行一些操作?

我用:

$('#shwall').ajaxStart(function(){ 
     $('#shwall').html("<img alt=\"loading...\" src=\"img/ajax_loading_new.gif\"/>");  
    }); 

和我的Ajax請求的代碼就像下面:

$.ajax({ 
     type : 'Post', 
     url : 'employee.jsp', 
     data: "emplist="+id, 
     success : function(data){ 
      $('#employeereport').html(data);       
     } 
    }); 

但當我每次發送ajax請求時,我的頁面包含多個ajax請求:

$().ajaxStart(function(){}); 

代碼運行,但我不想這樣我想運行特定的Ajax請求 讓我怎麼做到這一點的代碼,

在先進的感謝...

回答

2

使用

beforeSend:功能(){

像你使用成功。

參考:http://docs.jquery.com/Ajax_Events

你可以給這樣的:

$.ajax({ 
       type : 'Post', 
       url : 'employee.jsp', 
       data: "emplist="+id, 
       beforeSend : function() 
       success : function(data){ 
        $('#employeereport').html(data);      
       } 
       }); 
+0

由於其工作......這就是我想要的..... – swan

1

使用

beforeSend: function(){} 

$.ajax({ 
     type : 'Post', 
     url : 'urpage.jsp', 
     data: "data="+data, 
     beforeSend : function(){ 
         //code 
     }, 
     success : function(data){ 
        $('#dd').html(data);      
     } 
});