sawan
sawan

Reputation: 2381

How to do some action when ajax request send?

Hi I am sending request through ajax and I want process something when ajax request send

I have used:

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

and my ajax request code is like following:

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

but my page contains multiple ajax request when I send ajax request every time:

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

code runs but I dont want like that I want to run this code for particular ajax request so how do I do that

thanks in advanced...

Upvotes: 2

Views: 271

Answers (2)

savy
savy

Reputation: 164

use

beforeSend: function(){}

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

Upvotes: 1

Gaurav Shah
Gaurav Shah

Reputation: 5279

use

beforeSend: function(){

like you are using success.

reference : http://docs.jquery.com/Ajax_Events

you can give like :

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

Upvotes: 2

Related Questions