简体   繁体   English

页面重定向到php中的同一页面

[英]Page redirect to same page in php


I have two pages let say www.abcd/cont.php and www.abcd/sign.php 我有两页说www.abcd/cont.phpwww.abcd/sign.php
When i fill the form in www.abcd/cont.php and click submit , it shows an alert msg and redirect to the same page (ie www.abcd/cont.php) itself . 当我在www.abcd/cont.php填写表单并单击“提交”时,它会显示一个警报消息并重定向到同一页面(即www.abcd / cont.php)本身。
But instead of redirection, it is going to www.abcd/sign.php page itself. 但不是重定向,而是转到www.abcd/sign.php页面本身。

Here is my sign.php code 这是我的sign.php代码

if(success){
echo echo '<script language="javascript">';
      echo 'alert("send")';
      echo '</script>';
} else {
 echo '<script language="javascript">';
      echo 'alert("Not send")';
      echo '</script>';
}
header("Location: http://www.abcd/cont.php");
      exit();

i am getting the alert msg but not redirect to that particular page(www.abcd/cont.php) when i click ok on alert message. 当我在警报消息上单击“确定”时,我收到警报消息,但未重定向到该特定页面(www.abcd / cont.php)。
Can anyone suggest an idea to do this. 任何人都可以建议这样做的想法。

You can just change the URL in JavaScript: 您只需在JavaScript中更改网址即可:

if(success){
    echo '<script language="javascript">alert("send");window.location = "http://www.abcd/cont.php";</script>';
} else {
    echo '<script language="javascript">alert("Not send");</script>';
}

My best guess is that it is happening because you are already sending headers by using the echo function hence your Location() is not working, instead you can try this, 我最好的猜测是发生这种情况,因为您已经在使用echo函数发送标头,因此Location()无法正常工作,您可以尝试这样做,

if(success){
echo echo '<script language="javascript">';
      echo 'alert("send")';
      echo 'window.location.href=http://www.abcd/cont.php;';
      echo '</script>';
} else {
 echo '<script language="javascript">';
      echo 'alert("Not send")';
      echo '</script>';
}

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

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