简体   繁体   English

如何重定向到另一个页面?

[英]how to redirect on another page?

http://example.com/example/education_detail.php?uid=example@example.com ; http://example.com/example/education_detail.php?uid=example@example.com ; i want to redirect this url to another page but same url showing browser link bar so how can i change url. 我想将此网址重定向到另一个页面,但是显示浏览器链接栏的网址相同,所以我该如何更改网址。 my url code window.location.href="education_detail.php?uid=<?php echo htmlentities($user_id);?>"; 我的网址代码window.location.href="education_detail.php?uid=<?php echo htmlentities($user_id);?>";

Backend Code 后端代码

<?php
        if(empty($amount)){
            $error[] =  "Please Enter Expected Amount";
        }
        elseif(empty($cheque_name)){
            $error[] =  "Please Enter Issue Cheque in Favour of";
        }
        if (count($error)) {
            echo "<i class='fa fa-exclamation'> ";
            echo implode('<br>', $error);
            echo "</i>";
        }
        else{
            $result=mysqli_query($conn, "UPDATE education SET amount='$amount', cheque_name='$cheque_name', purpose_amount='$purpose_amount', date='$date' WHERE id='$apply_id'")or die("Could not insert data: " .mysqli_error($conn));
                echo 1;
        }
    ?>

below is ajax Jquery code 下面是ajax jQuery代码

$('.btn_education_step5').click(function(){            
    var formdata=new FormData($('#education_step5')[0]);
        $.ajax({
            url:'includes/backend_education_amount.php',
            method: "POST",
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            data : formdata,
            success:function(answer_from_actionpage){
                if(answer_from_actionpage == 1){
                    window.location.href="education_detail.php?uid=<?php echo htmlentities($user_id);?>";                   
                }else{
                    $('.error').html(answer_from_actionpage);
                }
            }           
        })
});

First confirm your echo htmlentities($user_id); 首先确认您的echo htmlentities($user_id); is print different user_id. 打印不同的user_id。

Without seeing the entire code of the backend script it is hard to determine what is wrong. 如果不查看后端脚本的完整代码,很难确定出什么问题了。 It looks like you might be echoing back more than just the "1" response and so your success handler is not correctly seeing the response you want. 看起来您可能回响的不仅仅是“ 1”响应,因此您的成功处理程序无法正确看到所需的响应。

In your backend script when you echo "1" be sure to stop the script from executing at that point if anything below that code has any output like HTML or other PHP logic. 在后端脚本中,当您回显“ 1”时,如果该代码下的任何内容具有诸如HTML或其他PHP逻辑的任何输出,请确保在该点停止执行该脚本。 I would change your echo to a die command to stop script execution and return a 1: 我会将您的回声更改为die命令,以停止脚本执行并返回1:

die(1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM