Working of JQuery Ajax and its parameters

AJAX allows web pages to update the data without reloading the whole page.

When the request is sent to the web server, it processes the request and the response will be sent back to the web page. The data will be processed by using javascript and necessary action will be performed.

Now let's create a simple ajax and see how it works.

jQuery(document).ready(function ($) {
$.ajax({
type:'Post',
url:'register',
data:'FetchDetails=Fetch&&id='+$("#id").val(),
dataType:'json',
success:function(data){

}
});
});

Ajax will be called when the page is loaded .Let's understand the working of each parameter.
type: Type of the request to make(Get/Post).
url: Contains the URL to which the request is sent.
data: The data string to send to the server when performing the Ajax request.It will be of the form key1=value1&key2=value2 .
dataType: The type of data expected back from the server.
success: It is a function which will be called when the request succeeds.The data in the function(data) indicates the parsed json object from the server.

Posted on by