在后端脚本之后重定向到新的URL

Sam*_*Sam 10 javascript php ajax jquery facebook

我有一个signup.php页面,其中包含通过facebook按钮登录.页面结构就是这样的

<?php
if(!isset($_SESSION['logged_in']))
{
    echo '<div id="results">';
    echo '<!-- results will be placed here -->';
    echo '</div>';
    echo '<div id="LoginButton">';
    echo '<a href="#" rel="nofollow" class="fblogin-button" onClick="javascript:CallAfterLogin();return false;">Login with Facebook</a>';
    echo '</div>';
}
else
{
    echo 'Hi '. $_SESSION['user_name'].'! You are Logged in to facebook, <a href="?logout=1">Log Out</a>.';
}
?>
Run Code Online (Sandbox Code Playgroud)

此页面上使用的ajax代码调用另一个页面process_facebook.php并在后端处理数据.在signup.php页面中用于ajax的代码是

<script type="text/javascript">
window.fbAsyncInit = function() {
    FB.init({
        appId: '<?php echo $appId; ?>',
        cookie: true,xfbml: true,
        channelUrl: '<?php echo $return_url; ?>channel.php',
        oauth: true
        });
    };
(function() {
    var e = document.createElement('script');
    e.async = true;e.src = document.location.protocol +'//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);}());

function CallAfterLogin(){
    FB.login(function(response) {       
        if (response.status === "connected") 
        {
            LodingAnimate(); //Animate login
            FB.api('/me', function(data) {

              if(data.email == null)
              {
                    //Facbeook user email is empty, you can check something like this.
                    alert("You must allow us to access your email id!"); 
                    ResetAnimate();

              }else{
                    AjaxResponse();
              }

          });
         }
    },
    {scope:'<?php echo $fbPermissions; ?>'});
}

//functions
function AjaxResponse()
{
     //Load data from the server and place the returned HTML into the matched element using jQuery Load().
     $( "#results" ).load( "process_facebook.php" );
}

//Show loading Image
function LodingAnimate() 
{
    $("#LoginButton").hide(); //hide login button once user authorize the application
    $("#results").html('<img src="img/ajax-loader.gif" /> Please Wait Connecting...'); //show loading image while we process user
}

//Reset User button
function ResetAnimate() 
{
    $("#LoginButton").show(); //Show login button 
    $("#results").html(''); //reset element html
}

</script>
Run Code Online (Sandbox Code Playgroud)

现在问题是process_facebook.php页面在后端使用fb数据,之后被重定向回signup.php页面并显示process_facebook.php页面打印的数据(可选).我想要的是,而不是从process_facebook.php页面重定向回signup.php页面并显示其数据,我希望重定向到另一个页面,不仅新数据应该从新页面加载,但网址也应该得到已更改.(即www.example.com/app/signup.php应更改为www.example.com/app/profile.php)

我忘了提,但我已经尝试使用header()重定向,但它只是获取profile.php页面的数据,但显示www.example.com/app/signup.php url ..现在的问题是,如果我出于任何原因刷新页面,然后加载旧signup.php页面的数据

a c*_*der 0

在将任何 HTML 输出到客户端之前,标头需要位于页面顶部。您还可以在服务器向下浏览页面时输出数据,将 HTML“写入”客户端。

在任何 HTML 之前,但在打开 PHP 之后,使用以下命令:

header('Location: http://www.example.com/');
Run Code Online (Sandbox Code Playgroud)

参考: http: //php.net/manual/en/function.header.php