Web Analytics Made Easy -
StatCounter XmlHttpResponse problems with Response.Redirect("...") - CodingForum

Announcement

Collapse
No announcement yet.

XmlHttpResponse problems with Response.Redirect("...")

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • XmlHttpResponse problems with Response.Redirect("...")

    I have the following problem:

    I am currently implementing AJAX (Asynchronous Javascript And Xml) into certain areas of my website. Anyway - it uses the JavaScript XmlHttpResponse object to send and receive data to and from the server without having to post back the page.

    Everything is working great, until I try to use a Response.Redirect() on the server side.

    Here is my example:

    I have a content page which is access restricted to registered users, and this is how it SHOULD work:

    1. The page (RestrictedPage.aspx) loads an empty template.
    2. Once loaded, I use the JavaScript XmlHttpResponse object to fetch content to fill the template (without reloading the page). I request data from, lets say, content.aspx
    3. content.aspx first checks to see that the user is logged in
    - 3.1) Not logged in - it redirects to an appropriate page to output the "access denied" XML
    - 3.2) Logged in - Redirects to appropriate page to output XML content
    4. Now the info is returned to the XmlHttpResponse object on the client side (RestrictedPage.aspx).
    5. I use JavaScript to work with the XML, and do appropriate things depending on what the returned XML is... (like tell the user to log in, or use DOM objects to fill the template with content)

    All of this works great WITHOUT redirects involved. My problem is that as soon as I use Response.Redirect() in step 3.1 or 3.2 above, instead of just the XmlHttpResponse URL redirecting, the actual client is redirected, and the browser loads what should be loading in the XmlHttpResponse object...

    I have a feeling there is no work around, but if anyone knows why this happens, please let me know!??

    Thanks!
    Bypass your proxy and get anonymous internet surfing FREE!

  • #2
    Yeah - Response.Redirect() actually sends a message back to the client, telling it to request the new page. So it's a bit carp anyway in that it forces another round trip to the server.

    I haven't tried it but does Server.Transfer() have the required effect?

    Comment


    • #3
      Originally posted by Spudhead
      Yeah - Response.Redirect() actually sends a message back to the client, telling it to request the new page. So it's a bit carp anyway in that it forces another round trip to the server.

      I haven't tried it but does Server.Transfer() have the required effect?
      Thanks for the response...
      Unfortunately Server.Transfer() does the same thing...
      Hmmm... It would have been nice if the XmlHttpResponse object handled all client related responses for the url it was submitting... Oh well.
      Bypass your proxy and get anonymous internet surfing FREE!

      Comment

      Working...
      X