I have an $.ajax() request with the dataType set to \"json.\" The server is returning JSON with the correct mime type of \"application/json.\" And yet the responseText in my
Step 1: Stringify the jqXHR
var errorString = JSON.stringify(jqXHR.responseText);
Step 2: change that string to Jquery Object
var $errorObj = $(errorString);
Step 3: Find and get what part of responseText you want.
var errorMessage = $errorObj.find('p').eq(1).text();
/* Here Im finding `Message:` thrown by the server, which is inside tag */
Thats it.
$.ajax( /* ... */ ).fail( function(jqXHR, textStatus, errorThrown) {
var errorString = JSON.stringify(jqXHR.responseText);
var $errorObj = $(errorString);
var errorMessage = $errorObj.find('p').eq(1).text();
alert(errorMessage);
} );