What is difference between contentType and dataType in jquery ajax method?

AJAX: AJAX is Asynchronous JavaScript and XML. AJAX is a new technique to create faster and better web application.

 

jQuery AJAX Methods:

AJAX is used to send data to server, without refreshing whole page. It reloads part of page when data is exchange to server.

$.ajax(
{
type: 'POST',
url: 'Default.aspx/GetData',
data: '{ }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {

}
}
);

Type:

It is type of request GET/POST which will be sent to server.

 

URL:

It is URL where request will be send. Default is the current page.

 

ContentType:

The content type is type of data we are sending to server. Default is: “application/x-www-form-urlencoded,charset=UTF-8”

 

dataType:

DataType is what we are expecting response from server.

Ex: json, html, text etc.

 

 

Please provide your comments.

Happy coding. Smile