Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I were doing similar thing on Zend/PHP project. Unfortunately, I'm not familiar with Java and there I can suggest only basic direction. </p> <p>By default, XMLHttpRequest execute redirects. So if you do a redirect during ajax request, XMLHttpRequest will execute it without letting you know that redirect happened at all. At least I found no way to catch such situation and handle it somehow. Because of that, on server side I override a redirect method. Suppose you can do something like that in Java too. Once request came from ajax (you can add a some specific header to your ajax request and check it on server) you can return a header different from <code>Location</code> header. For instance, <code>New-Location</code>, and do no actual redirect. Just stop request execution.</p> <p>On client side you can use <a href="http://api.jquery.com/jQuery.ajaxSetup/" rel="nofollow">jQuery.ajaxSetup</a> to configure global handler for all ajax requests at once. Here is how you can add a header to all requests with <code>.ajaxSetup</code>:</p> <pre><code>$.ajaxSetup({ headers: { XHTTPRequest: 'true' } }); </code></pre> <p>Additionally you can set a global <a href="http://api.jquery.com/ajaxSuccess/" rel="nofollow">ajaxSuccess</a> and <a href="http://api.jquery.com/ajaxError/" rel="nofollow">ajaxError</a> handlers. They will be executed before any success/error handler of a separate ajax request. In global ajax success you can take a header from <code>xhr</code> object passed as a third parameter to callback function and do a redirect:</p> <pre><code>var newLocation = xhr.getResponseHeader("New-Location"); if(newLocation) document.location = newLocation; </code></pre> <p>Basically, you can return special object instead of header or find some other way to pass a new location to your <code>ajaxSuccess</code> callback. </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