How can I tell whether the returned data of a successful $.ajax() is of html or json?
jquery
Solution
For json data, `typeof(data)` will be `object`. For html data it will be `string`.
At least with data returned from ASP.NET MVC3 actions it works. I assume that it is the mime type that decides how jquery handles the returned data.
Problem
I have a form that gets submitted to the server via jQuery `.ajax()` POST. If the form passed the validation on the server-side, the server would return result in HTML for the client-end to update its presentation accordingly. If, however, the form failed the validation, the server would return result in JSON, which consists of the validation errors. Both types of result would end up in the `success` handler of `.ajax()`. Since both types are possible, the handler needs a way to determine whether the result is HTML or JSON. How can I do that? Note: On the surface, my question looks like the same as this existing SO question but they are not the same. In that question, there's only one possible datatype (HTML or JSON), while my problem is about finding a way to deal with two possible datatypes (HTML and JSON).