开发者

redirecting an ajax processing page

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 tha开发者_运维百科t'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?


  • 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;
        }
    });
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜