Jquery Ajax Post Example

Posted on  by admin

In jQuery AJAX POST Example, I have covered how to make AJAX Post requests with jQuery API.

  • 1.Ajax POST example using .ajax() method2.Ajax POST example using .post() method3.AJAX Form POST example. Sample POST request look like:.
  • To send, POST request you need to set type = “POST” in AJAX settings.formData: can be an array or name value pairs.success: callback function is called when the AJAX POST is successfulerror: callback function is called when the AJAX POST is failed.
  • Note: To handle JSON data, set dataType=”json”. $.post() method is shortcut of .ajax() method, so using $.post() method we can send AJAX POST requests.
  • jQuery.post() Syntax:. Valid AJAX POST Requests are:. $.post method is not having any callback method to handle errors. But we can use jqXHR fail() callback method to handle the error.

Additional Notes:

Below is the sample Form used for POST. Using jQuery.serialize() or jQuery.serializeArray() API, Form data can be serialized.

Below example shows how to POST Form data asynchronously. For multipart/form-data Form post, check this: http://hayageek.com/jquery-ajax-form-submitReference:Jquery Documentaion.

Learn to utilize the full power of AJAX with jQuery to make application development easy, fast as well as effective.

In the root of jQuery Ajax is ajax() function. This function is used to perform HTTP requests which are by default asynchronous.

Recommended jQuery Tutorials

The syntax for using this function is:. The parameters specifies one or more name/value pairs for the AJAX request.

Possible names/values in the table below:. A Boolean value indicating whether the request should be handled asynchronous or not.

Related Posts:

Default is true. Please note that as of jQuery 1.8, the use of async: false is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().