I’m using jquery get to call an ASP MVC controller. Which returns a partial view. i.e. a bunch of html
In the case of an error I’d like to populate some info for the user but ASP MVC is sending a full page back so I need to grab text out of it.
I’ve tried:
$('#edit').ajaxError(function (e, xhr, settings, exception) {
var item = xhr.responseText.text();
var response = item.match(/.*<body.*>(.*)<\/body>.*/);
if (!response) {
$(this).html('Error: ' + xhr.status + ' Message:' + xhr.statusText);
}
else {
$(this).html(response);
};
});
But I get Uncaught TypeError: [followed by the contents of xhr.responseText] has no method text
If I call match directly on responseText I get null as a result.
I’m guessing I’ve got some fundamental misunderstanding going on so if anyone can help…
You should also modify your regular expression to include newline characters, i.e.