I\'m trying to return an error message via Json from ASP.NET MVC controller. I want to display carriage returns on the screen, so the error will look like:
It seems to me that you already made almost everything correct. The results which you have in the xhr.responseText
is a JSON string. So you should insert only one additional call of the JSON.parse
function
.ajax({...
error: function(xhr, textStatus, exceptionThrown) {
$('#result').html(JSON.parse(xhr.responseText));
},
then the data like '"Error1.\u003cbr/\u003eErro2.\u003cbr.\u003e"'
will be converted to the string 'Error 1.
.
Error 2.
'
Inside of success
event handler the ajax
function call JSON.parse
for you, but it do this not inside of the error
handler. So converting the server response from JSON string you have to do manually.