Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6083209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:22:34+00:00 2026-05-23T11:22:34+00:00

My situation is, I’m developing a little web app where the server provides dynamic

  • 0

My situation is, I’m developing a little web app where the server provides dynamic JSON responses. The server is built on cherrypy. Sometimes, there is a bug in the code creating the JSON data, which throws, and cherrypy catches it and serves back a 500-error with a full HTML page detailing the exception. (That is, the response has everything: <!doctype..><html><head>...</head><body>...</body></html>)
But because the request is AJAX, it doesn’t get displayed.

I can intercept this error easily enough, and look at it in the dev tools; but what I’d like to do (to ease debugging) is open a new page (as if user had followed a link) and display that response in the browser. I tried

window.open('', '_self');
$(document).html(jqXHR.responseText);

but I just get a blank page. I suppose I could store the error text and serve it up in a second request to the server, but is there a cleaner way?


To follow up, the final code that worked was this:

.error(function(jqXHR, textStatus, errorThrown) {
    $(window).bind('unload', function() { document.write(jqXHR.responseText); } );
    var win = window.open('', '_self');
    return false;
});

Not sure if that final return false is necessary but it seems good form.


Following up again: the above code worked reliably in Opera. I thought I had seen it working in Webkit as well, but I started noticing that it wasn’t; and on further testing, it wasn’t working for Firefox either.

What I found that worked in all three platforms was this:

document.open('text/html', true);
document.write(jqXHR.responseText);
document.close();

Don’t have to open another window or bind events; just re-open the document and stuff the text in there.


Well, here I am again. The above technique either stopped working or I was tripping when I said it ever worked at all. Chrome, in particular, doesn’t seem to have document.open defined.

But! I just found a nifty technique that seems to work everywhere:

errtext = 'data:text/html;base64,' + window.btoa(jqXHR.responseText);
window.open(errtext, '_self');

This simply converts the response into a fully self-contained data: URL and opens it in the window.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:22:35+00:00Added an answer on May 23, 2026 at 11:22 am

    Try this:

    var win = window.open('', '_self');
    win.document.getElementsByTagName('Body')[0].innerText = jqXHR.responseText;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation Let's take the following design: App servers DB servers - Server A -
Situation Well, as you can see below, I have a main App, creating a
Situation: jax-ws web service on Weblogic appserver; wsdl first development, jaxb customizations in external
Situation: a user clicks on a link, the server gets the request and starts
Situation: Hello! I have a little problem in a C# project. I am using
Situation: The UI of an app is based on a UISplitView with two UINavigationController
Situation: Large company with several internal Java applications that launched via Java Web Start
Situation: running a Google App Engine site with my static content's default_expiration set to
Situation There is a high chance that users will not interact directly with the
Situation: WPF application, .NET4, DataSource (MS SQL Server 2008) created with the designer Problem:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.