在PHP开发过程中,表单提交后跳转是常用到的技术。一般可以用js的
js例子:
echo “<script> alert(‘sucess’);window.location.href=’/product/index’; </script>”;
每次都复制一大段代码还是比较麻烦的,我们可以考虑封装成函数来调用,下面是我自己封装的页面跳转函数
页面跳转函数封装
/**
* 页面跳转方法
* @param $msg 提示说明
* @param null $path 跳转路径
* @param null $parent 例子ture返回父窗口
*/
function messageInfo($msg,$path=NULL,$parent=NULL){
if($parent === true){
$str=”<script>alert(‘”.$msg.”‘);parent.location.href='”.$path.”‘</script>”;
}else if(empty($path)){
$str=”<script>alert(‘”.$msg.”‘);history.back()</script>”;
}else{
$str=”<script>alert(‘”.$msg.”‘);location.href='”.$path.”‘</script>”;
}
echo $str;
}
使用方法:
messageInfo(‘操作成功!’,’http://www.demourl.com/product_list.php’);

