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

You must have heard about AJAX, if you have worked on web application.

Let’s see what is AJAX and what is the difference between contentType and dataType in the jquery ajax method?

AJAX is Asynchronous JavaScript and XML.

It is used for partial page refresh.

AJAX is a new technique to create faster and better web applications.

 jQuery AJAX Methods:

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

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

}
}
);

Type:

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

 URL:

It is a URL where requests will be sent. The default is the current page.

 ContentType:

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

 dataType:

A dataType is what we are expecting a response from the server.

Ex: json, html, text etc.

Conclusion:

AJAX is Asynchronous JavaScript and XML.

It is a new technique to create faster and better web applications.

Hence now you must have understood “What is the Difference between contentType and dataType in the jQuery ajax method?

 Please provide your comments.

Happy coding.

Smile
  • Save

  • Save

Hits: 4322

12 thoughts on “What is the difference between contentType and dataType in the jquery ajax method?”

  1. Hello there, just became aware of your blog through Google, and found that it is truly informative. I am going to watch out for brussels. I抣l appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers!

    Reply
  2. Valuable information. Lucky me I found your site by accident, and I’m shocked why this accident did not happened earlier! I bookmarked it.

    Reply
  3. I just want to mention I am just very new to blogging and site-building and truly savored your blog. More than likely I’m planning to bookmark your site. You definitely come with exceptional writings. Kudos for sharing with us your web-site.

    Reply

Leave a comment

0 Shares
Share via
Copy link
Powered by Social Snap