Well, the easy answer is just send JSON in both cases, with the HTML as part of the JSON response. $.ajax returns the XMLHttpRequest that it creates, so you could get the content type in your success function and eval the JSON yourself:
var xhr = $.ajax({ ... success: function(data){ console.log( xhr.getAllResponseHeaders() ); console.log( xhr.getResponseHeader('Content-type') ); } }); On Aug 5, 7:53 am, moltar <roman.filip...@gmail.com> wrote: > Here is a scenario. I am submitting a form via AJAX. The form may > either return HTML (when there are input errors) or JSON (successful > response). If during request I specify "dataType: 'json'" then HTML > doesn't get thru correctly, if I don't then JSON is displayed as plain > text. > > I am sending the "application/json" header back correctly. I don't > understand why doesn't jQuery just pick that up and parse it as JSON? > Is there an option? Is there something I can do to make this work? > > Thank you!