I'm having some issues catching error messages from a controller via .ajax error. The script is called by a jQuery UI Dialog popup. Any help would be appreciated.
Here's the code snippet from my controller
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content("There was an error in your request.", MediaTypeNames.Text.Plain);
and here's the jQuery script:
function submitFormWithAjax(form) {
form = $(form);
$.ajax({
url: form.attr('action'),
data: form.serialize(),
type: (form.attr('method')),
dataType: 'text',
error: function(data) {
$('#result').html(data);
},
success: function(data) {
$('#result').html(data);
setTimeout("reloadPage()", 500);
}
});
return false;
}
The error: function(data)
isn't reading the returned error message. Any suggestions?