using ajax beforeSend to modify data

Viewed 31672

Let's say I have an Ajax call from jQuery like this:

$.ajax({
   url: myUrl,
   data: myData,
   type:'post'
});

I would like to be able to add to the myData using

$.ajaxSetup({
   beforeSend: function(call){...}
});

The result should be that all ajax calls (both post and get) is modified so if i get an extra parameter IsAjax=true

3 Answers

You can just actually use beforeSend in $.ajax();

$.ajax({
  beforeSend: function(xhr){
    this.data += '&' + $.param({
      param: 'test'
    });
  }
});
Related