显示警报消息并重定向页面

时间:2018-11-13 07:33:41

标签: javascript php codeigniter

我有以下代码。失败时,我需要获取警报已经存在并重定向到te注册页面。但是成功后,我需要检查会话,并根据角色ID,我需要重定向页面,但是在这种情况下不会发生警报和重定向...您能告诉我我错了吗

if ($referral_patient_id != NULL) {
    echo "<script language='javascript'>
    alert('Successfully Added');
    if ($_SESSION['role_id'] != 6) {
        echo 'window.location.href="../Laboratory_Home"';
    } else {
        echo 'window.location.href="../Billing_Home"';
    } </script>";
} else {
    echo "<script language='javascript'>
    alert('Already Exists');
    window.location.href = '../../LabAdd_Patients'; 
    </script>";
}

3 个答案:

答案 0 :(得分:2)

<?php if ($referral_patient_id != NULL) { ?>
    <script type='javascript'>
    alert('Successfully Added');
<?php  if ($_SESSION['role_id'] != 6) { ?>
     window.location.href="../Laboratory_Home";

<?php } else {  ?>
       window.location.href="../Billing_Home";
<?php  }  ?>
</script>
  <?php  }else { ?>
      <script type='javascript'>
         alert('Already Exists');
        window.location.href = '../../LabAdd_Patients'; 
  </script>
   <?php } ?>

试试这个家伙。

答案 1 :(得分:1)

您有混合的内容。 PHP和Javascript。试试这个

echo "<script language='javascript'>
        alert('Successfully Added');
     </script>";

if($_SESSION['role_id']!=6){
  echo "<script language='javascript'>window.location.href='../Laboratory_Home'</script>";
} else {
  echo "<script language='javascript'>window.location.href='../Billing_Home'</script>";
}

或者这个

echo "<script language='javascript'>
        alert('Successfully Added');
        if( ".$_SESSION['role_id']." !=6) {
            window.location.href='../Laboratory_Home';
        } else {
            window.location.href='../Billing_Home';
        }
    </script>";

答案 2 :(得分:1)

Try this javascript code :

<script language='javascript'>
var referral_patient_id = '<?php echo $referral_patient_id; ?>';
if(referral_patient_id != null)
{
    alert('Successfully Added');
    var role_id = '<?php echo $_SESSION["role_id"]; ?>';
    if (role_id != '6') {
        window.location.href="../Laboratory_Home";
    } else {
        window.location.href="../Billing_Home";
    }
} 
else
{
    alert('Already Exists');
    window.location.href = '../../LabAdd_Patients'; 
}
</script>