By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,636 Members | 1,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,636 IT Pros & Developers. It's quick & easy.

AJAX Redirect

P: n/a
ses
How do i implement server side redirect when the request was submitted
using AJAX?

Sep 7 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.