Friday, April 23, 2010

jQuery $.ajax call with parameters

I always forget the exact syntax and waste time searching for an example on the web.

   1:  $.ajax({
   2:      type: "POST",
   3:      url: "Default.aspx/WebMethodWithParameters",
   4:      data: { param1: $('#val1').val(),
   5:              param2: $('#val2').val(),
   6:              param3: $('#val3').val()
   7:          },
   8:      success: function(msg) {
   9:          //on success callback
  10:      },
  11:      error: function(msg){
  12:          //on error callback
  13:      }
  14:  });

more info on the jQuery help page