2

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'
bikram kc
  • 846
  • 1
  • 14
  • 18

1 Answers1

3

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.

Community
  • 1
  • 1
Knetic
  • 2,099
  • 1
  • 20
  • 34