Replace current page with ajax content
ajax, html, javascript, jquery
Solution
Configure jQuery ajax setup as follows:
$.ajaxSetup({
error: handleXhrError
});
where `handleXhrError` function look like this:
function handleXhrError(xhr) {
document.open();
document.write(xhr.responseText);
document.close();
}
See also:
- Handling of server-side HTTP 4nn/5nn errors in jQuery
Problem
I have a page with a dialog window which sends ajax post data to server and receives a response. During development, there can be two responses - one regular (this is not the question) or one with an error. Server returns code 500 and a page with lot of debug informations. This is a regular page returned from a framework and contains some javascript code. I want to be able to display this error page in case it happens. The problem is, I can not simply attach the returned result to body element or open a new link in a new page and load this error again. I simply get a html page instead of data and I have to display the page (in current window or in another one). I am using jQuery.