Monthly Archives: November 2016

Ajax using jQuery

Ajax stands for asynchronous JavaScript. You can use “ajax” method to make ajax calls in jQuery.

Here is the syntax of ajax method.It takes json object as a parameter.

ajax({p1:v1,p2:v2,…..and so on})

For example – To invoke the code from “getData.php” server file, you can use below syntax. Note that we have used “url” property to specify the server file. Also we have used “success” property to specify the function to be called when response is sent by the server.

$.ajax({url: “getData.php”, success: function(response){
console.log (“Ajax response is ” + response)
}});

ajax method accepts below types of properties in json parameter.

  1. type – type of HTTP request (GET or POST)
  2. data – data to be sent to the server
  3. contentType – content type of the data to be sent to the server
  4. async – This can be used to specify if the request is synchronous or asynchronous