469,327 Members | 1,292 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

AJAX Redirect

ses
How do i implement server side redirect when the request was submitted
using AJAX?

Sep 7 '06 #1
7 31293
You don't. That's why you use Ajax in the first place. If your request
results in a need for a new page load then you've missed the entire
point.

Sep 7 '06 #2
ses wrote:
How do i implement server side redirect when the request was submitted
using AJAX?
Same way as normal (and then XMLHttpRequest will make another request to the
new URL and get the data from there).

A redirect response to an XMLHttpRequest cannot directly change the URL that
user is viewing (since the request that the page was returned from is not
the one being redirected).

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 7 '06 #3

Tom Cole wrote:
You don't. That's why you use Ajax in the first place. If your request
results in a need for a new page load then you've missed the entire
point.
That being said, you'll have to perform the redirect client side in the
callback handler for the XmlHttpRequest. You can do this by setting the
document.location value.

Sep 7 '06 #4
ses
I found this strage as the W3C XMlHttpRequest specification says that
the redirect should be handle as normal.

So I created a Page that accepts AJAX Requests and sends back a status
of 302 think it would redirect the page put it did. So while i take you
point but i was programming to specification.

Sep 7 '06 #5
ses wrote:
I found this strage
You find what strange? Please quote.
as the W3C XMlHttpRequest specification says that
the redirect should be handle as normal.
And it is handled as normal. A redirect means "The resource you requested
can actually be found here", not "Point the main window of the browser to
this other URL".

If the resource being requested is supposed to be handled by an
XMLHttpRequest object, then the resource at the other end of the redirect
will be.

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 7 '06 #6
ses

W3C states:

If the response is an HTTP redirect (status code 301, 302, 303 or 307),
then it MUST be transparently followed (unless it violates security,
infinite loop precautions or the scheme isn't supported). Note that
HTTP [RFC2616] places requirements on UAs regarding the preservation
of the request method during redirects, and also requires users to be
notified of certain kinds of automatic redirections.

I am slowly understanding so you are saying if I want the request to be
handle by another page PageB.aspx it would pass all the parameters. But
not change the window location.

Sep 8 '06 #7
ses wrote:
I am slowly understanding so you are saying if I want the request to be
handle by another page PageB.aspx it would pass all the parameters. But
not change the window location.
What happens:

XMLHttpRequest requests PageA.
The server returns a redirect response.
XMLHttpRequest requests PageB and handles it.

What doesn't happen:

XMLHttpRequest requests PageA.
The server returns a redirect response.
The main browser page viewing thingy[1] requests PageB and handles it.
[1] &trade;

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 9 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Grzegorz Smith | last post: by
5 posts views Thread by Martin | last post: by
2 posts views Thread by archana | last post: by
5 posts views Thread by Mike | last post: by
2 posts views Thread by Angel666 | last post: by
1 post views Thread by =?Utf-8?B?TWlrZQ==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.