View Full Version : Ext.Ajax automatically redirects when return code is 302 and there is a Location head

23 Jan 2013, 2:32 PM
In this example I am making ajax request. It returns a response 302 (redirect) and Location header set to something I want to access. I also need to access the rest of the response headers, unfortunately the response I am getting contains not my original response, but a second one automatically done with a URL set in Location header. This is somewhat logical, but I do not want this to happen automatically, I want to handle it myself...

url: url,
params: {},
callback: function(options, success, response){

// response here contains response info for the second request doe automatically based on
// the location header

scope: this

24 Jan 2013, 9:44 AM
What values are you getting back in your callback parameters?

What do you see using:

Ext.Ajax.on('beforerequest', function(conn, response, options) {

Ext.Ajax.on('requestcomplete', function(conn, response, options) {
if (response.responseText && response.status === 0) {
response.status = response.text ? 200 : 404;

Ext.Ajax.on('requestexception', function(conn, response, options) {


25 Jan 2013, 12:51 PM
Hi Scott,

Thanks for your reply. I've changed my post... the issue seems to happen with 302(redirect) responses. It automatically redirects and I get failure, because the URL it redirects is not valid...

25 Jan 2013, 12:52 PM
It there a way to tell Ext.Ajax to not automatically redirect when the response is 302 with Location header?

25 Jan 2013, 2:28 PM

Looks like Browser's XMLHttpRequest is doing the redirect. There is a workaround to tell it to not redirect by setting a variable to 0. Does ExtJs expose it?

25 Jan 2013, 4:10 PM
Indeed, the redirect is performed by the browser, not ExtJS.

I suspect the workaround you mentioned won't work cross-browser, a quick bit of searching suggests that the channel property is only available in Gecko.

If you only care about Firefox then you could apply the workaround with a small amount of tweaking. Personally I'd probably override openRequest (a method Ext.Ajax inherits from Ext.data.Connection).