9951 explained code solutions for 126 technologies


jqueryHow can I use jQuery AJAX to make a POST request?


jQuery AJAX is a powerful tool for making asynchronous requests to the server. It can be used to make a POST request to the server. Here is an example of how to do it:

$.ajax({
  type: "POST",
  url: "url_to_post_to",
  data: {
    name: "John",
    age: 25
  },
  success: function(data) {
    console.log(data);
  }
});

This code will make a POST request to the URL specified in url, with the data name and age specified in the data parameter. The success function will be called when the request is successful, and the response data will be passed to it.

The parts of the code are:

  • type: specifies the type of request, in this case POST
  • url: the URL to send the request to
  • data: an object containing the data to be sent in the request
  • success: a function to be called when the request is successful

Helpful links

Edit this code on GitHub