O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using a jQuery .post() AJAX Request to Update Server Data

var params = [{name:"user",value:"Brad"},               {name:"rating", value:"1"}]  $.post("setRating.php", params, myHandler);

Using jQuery to post data to the server is easy with the .post() helper method because .post() handles all the necessary headers in the background. You call the .post(url, params, handler(data)) method and pass in the url to the server location, parameter string, or object. Then you specify a handler to handle the data.

If you pass in an object, it needs to be a list of objects with name and value pairs. For example:

var params = [{name:"user",value:"Brad"},               {name:"rating", value:"1"}] ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required