Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajaxy - add parameters to request

Tags:

jquery

ajax

I am using the jQuery Ajaxy plugin: http://balupton.com/projects/jquery-ajaxy

Is there a way to add POST parameters to each Ajaxy request?

like image 244
luksak Avatar asked Apr 11 '11 08:04

luksak


2 Answers

You can use $.ajaxSetup() to set default options - including (GET/POST) data.

$.ajaxSetup({
    data: { foo: 'bar' }
});

These data will be merged with your data specified in the $.ajax() call.

$.ajax({
    type: 'POST',
    url: '/test',
    data: { abc: 123 },
    success: function(resp) { }
});

This will send both foo and abc.

You can also move other options like type: 'POST' into your defaults so you don't have to specify it everytime.

like image 59
ThiefMaster Avatar answered Oct 02 '22 16:10

ThiefMaster


According http://visualjquery.com you can also go this way:

 $.ajax({
  type: "POST",
  url: "some.php",
  data: "name=John&location=Boston",
  success: function(msg){
  alert( "Data Saved: " + msg );
 }
});
like image 41
Reporter Avatar answered Oct 02 '22 15:10

Reporter