0

I have a page that checks to see if the user logged in and if the user is not, uses an jQuery ajax call to a php processing page to get the information. But to get the information it has to redirect out to the 'login site' which sits on a different server, and the 'login site' then POSTs back the login information to the php page, and the php page turns the raw data into something the first page can understand.

Well at least that's what's suppose to happen.

What actually happens is that once the php processing page redirects I get a 302 error. I've tried going to the php page without the ajax call to it and it works fine, redirecting to the 'login site' and accepting the post back.

I can't remove the ajax call and just code the bounce into the first page because the page is html, unfortunately it has to stay that way, and html pages don't like POSTs to them and crash.

Below is the code with the ajax call...

if (Login == null) {
    $.get("some_php_page.php", {  }, function(data) {
        if (data == "") {

        } else {
        //set login cookie;
        }
    });
}

Below is the php processing page...

if ($RefererServer != LoginServer) {
    header( "Location: LoginServer/verify.php");
} else {
    // send login information back
}

Anyone have any idea?

nroscoe
  • 93
  • 1
  • 7
  • You should read this thread, i think it addresses your problem: http://stackoverflow.com/questions/199099/how-to-manage-a-redirect-request-after-a-jquery-ajax-call – Johnny Craig Aug 26 '11 at 16:49
  • Remember that AJAX calls are subject to same-origin security policies. Redirect the ajax call to a completely different server is HIGHLY likely to trigger the security policy and kill the request. – Marc B Aug 26 '11 at 16:50
  • How is 302 an error? It is the code typically used to for redirection. – AppleGrew Aug 26 '11 at 17:05

1 Answers1

0
  • On the server side, you should return a json:

    { "success: false, "redirect": http://redirecturl.com }

  • On the client side, redirect is made by js

    $.ajax({
        // ....
        success: function(response){
            window.location = response.redirect;
        }
    });
    
Klaus
  • 451
  • 5
  • 8