How does the jQuery - ContentType tell javascript the specific data I want to display?
So jQuery documentation state that the default for contentType is 'application/x-www-form-urlen开发者_C百科coded. I was making a call to a web method that returned a bool, but if I specified dataType as 'json' and didn't specify the contentType (expecting it to default) I could see in debug that a string was returned that included my bool (but more data as well).
But if I specified application/json; charset=utf-8 it would just return the bool (or at least after it parsed the return data).
So my larger question besides the question in the title - how do I determine the dataType and contentType when determining what I want to get back from a web method?
contentType tells the server what type of data you are sending it. dataType tells jQuery what type to expect the server to return. If dataType is set to json, then jQuery will parse the response from the server to a json Object.
Depending on what server technology you are using, contentType may or may not matter. But it's always best to specify if you are unsure.
精彩评论