I have seen return type json , application/json while working with ajax. I have tried both and found the same result. Please anyone let me know the difference between these two.
datatype: 'json'
datatype: 'application/json'
I have seen return type json , application/json while working with ajax. I have tried both and found the same result. Please anyone let me know the difference between these two.
datatype: 'json'
datatype: 'application/json'
JQuery's datatype
argument on the $.ajax
method accepts either the name of a format (like json
or xml
) which jQuery knows how to parse, or a MIME type (like application/json
), which jQuery can map back to a parseable type. In this case, jQuery is mapping application/json
to json
for you, because it's a common format.
The datatype
argument is not what MIME type you expect from the server, but how jquery should parse the response.
The documentation for jQuery.ajax
says:
dataType (default: Intelligent Guess (xml, json, script, or html))
Type: String
The type of data that you're expecting back from the server.
[...]
"json": Evaluates the response as JSON and returns a JavaScript object.