无法使用 PHP 显示警告消息
Can not display alert message using PHP
我在尝试使用 PHP 显示警报消息时遇到一个问题。我在下面解释我的代码。
<?php
if($id){
$message = "Added successfully.";
echo "<script type='text/javascript'>alert('$message');</script>";
header("location:http://localhost/crm_complain/index.php");
}else{
$message = "Unable to add.''nTry again.";
echo "<script type='text/javascript'>alert('$message');</script>";
header("location:http://localhost/crm_complain/index.php");
}
?>
在这里,我的问题是警报消息框根本不起作用。我需要在 if/else 条件内警报消息应该有效。请帮助我。
警报消息工作正常,但标头无法正常工作。如果要在收到警报消息后重定向,请尝试以下操作:
die('<script>location.href = "'. $url .'"</script>');
你不能得到这样的警报,因为你使用的是header()。您可以按以下方式解决此问题:
您的 PHP 代码(传递成功状态):
<?php
if($id)
{
//$message = "Added successfully.";
header("location:http://localhost/crm_complain/index.php?success=1"); // success status
}
else
{
//$message = "Unable to add.''nTry again.";
header("location:http://localhost/crm_complain/index.php?success=0"); // failure status
}
?>
您需要在 index.php 文件中添加以下代码以获取警报:
<script type="text/javascript">
var phpVar = "<?php if(isset($_GET['success'])) {echo $_GET['success'];} else { echo ""; } ?>";
if(phpVar == 1){
alert('Added successfully.');
}
else if(phpVar == 0){
alert('Unable to add.''nTry again.');
}
else{
// nothing
}
</script>
相关文章:
- Jquery单击按钮时不显示警告框
- 有一种方法可以使jslint在使用控制台时显示警告或错误
- 如何根据所选日期显示警告
- 在 中显示警告框 asp.net 将重定向到空白页,然后返回到原始页面
- 推送提交后,如果输入字段为黑色,则显示验证检查或以红色字母显示警告
- 带有合成和 Eslint 的 VIM:显示警告
- 功能点击不起作用...不显示警告框
- 无法使用 PHP 显示警告消息
- Plupload-在使用Flash Runtime且浏览器没有Flash时显示警告
- 如果在指定日期内,则使用日期选择器显示警告消息
- 删除行时,数据表显示警告
- 当用户第一次关闭特定页面时显示警告消息
- 如何在一半时间使用javascript完成在线考试时显示警告框
- Javascript函数不显示警告框
- 禁止在窗口上显示警告消息.打开
- 关闭弹出窗口时显示警告信息
- Javascript不显示警告消息
- ie浏览器显示警告值“未定义”;但火狐和chrome显示出了实际价值
- 如何使用Jquery保存数据后显示警告消息
- 如何将表单提交操作从显示警告弹出窗口更改为重定向到新页面?