What is the difference between
contentType: "application/json; charset=utf-8",
dataType: "json",
vs.
contentType: "application/json",
dataType: "text",
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
contentTypeis the HTTP header sent to the server, specifying a particular format.Example: I’m sending JSON or XML
dataTypeis you telling jQuery what kind of response to expect.Expecting JSON, or XML, or HTML, etc. The default is for jQuery to try and figure it out.
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:
The second: