What is Content Type and Datatype in AJAX Call

When we use an Ajax request in a webpage for loading content without page reload, the two most common term comes to use that is content type and datatype.

So before using these things in Ajax request we should understand what is the use of content type and datatype in Ajax request.

Let’s see these terms in detail.

Content Type :

This is type of data which we send to server.

Commonly application/json is used as content Type.

ex.

contentType: “application/json”

DataType :

This is type of data which we expect back from Server.

ex.

Json, html, text etc

Also Read:

How to Make AJAX Call on Same Page
Ajax Contact Form Using jQuery and PHP
Ajax Image Upload With jQuery and PHP

How to Use Content-type and datatype in AJAX Call.

Content-type and datatype example.

$.ajax({     
type : "POST",
url : "filename.php",
dataType : "text",
contentType: "application/json",
data : dataValue,
success : function() {
},
error : function(error) {
}
});

Hope you have understand what is difference between dataType and contentType in jQuery Ajax Call. If you any question regarding this article, feel free to comment.

Leave a Reply

Your email address will not be published. Required fields are marked *