Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Quite frankly, I think that approach is basically broken by design. You shouldn't have to make that decision at that place. For example, the ajax response could only signal that a whole new page should be loaded and the new content then be generated on a second (non-ajax) request to a new URL.</p> <p>In case you're forced to take the way you already go, and provided the response content is not very large, you could try Javascript-URIs. Basically, an URI in the form of <code>javascript:"string"</code> will load a new page which that string is the source code for. So, if <code>response</code> already is a string, just assigning <code>javascript:response</code> to <code>window.location.href</code> should suffice. Maybe you have to do some escaping beforehand. And I don't know, how cross-browser-compatible this approach is.</p> <pre><code>&lt;a href="javascript:response"&gt;load&lt;/a&gt; </code></pre> <p>is also possible.</p> <p>A variant of this is building the URL not with the variable name, but with the actual string data. Like</p> <pre><code>function source2url(src) { // make valid javascript string from source text var esc1 = src .replace(/\\/g, '\\\\') .replace(/\'/g, '\\\'') .replace(/\x0A/g, '\\x0A') .replace(/\x0D/g, '\\x0D'); // make valid url from that return "javascript:'" + encodeURIComponent(esc1) + "'"; } window.location.href = source2url(response); </code></pre> <p>This will, of course, generate pretty large URIs. And you'll always have the Javascript-URI in the address bar.</p> <p><strong>UPDATE</strong></p> <p>A similar approach is to use base64 encoding in a data URI. The <a href="http://en.wikipedia.org/wiki/Data_URI_scheme" rel="nofollow noreferrer">Wikipedia entry</a> explains how it works, including a javascript example. However, you'd have to <a href="https://stackoverflow.com/questions/246801/how-can-you-encode-to-base64-using-javascript">base64-encode</a> the content somehow. (Note: You can use data URIs with or without the base64 encoding. You have to see what gives you shorter URIs for your specific content.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload