what is the difference between
contentType: "application/json; charset=utf-8",
dataType: "json",
vs.
contentType: "application/json",
dataType: "text",
what is the difference between
contentType: "application/json; charset=utf-8",
dataType: "json",
vs.
contentType: "application/json",
dataType: "text",
contentType is the header sent to the server, asking for a particular format.dataType is you telling jQuery what kind of response to expect.
The $.ajax() documentation has full descriptions of these as well.
In your particular case, the first is asking for the response to be in utf-8, the second doesn't care. Also the first is treating the response as a javascript object, the second is going to treat it as a string.
So the first would be:
success: function(data) {
//get data, e.g. data.title;
}
The second:
success: function(data) {
alert("Here's lots of data, just a string: " + data);
}
as per docs:
"json": Evaluates the response as JSON and returns a JavaScript object. In jQuery 1.4 the JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. (See json.org for more information on proper JSON formatting.)"text": A plain text string.