JavaScript警报和php标头 [英] Javascript alert and php header

查看:78
本文介绍了JavaScript警报和php标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题.当我得到没有标题的PHP脚本时,这很好,我将收到javascript警报框.但是,当我在警报之前使用标头时,它不起作用.它像应有的重定向我,但未显示任何框.有人可以帮我吗?

I got a little problem. When I got my PHP script without header it's fine, I am getting javascript alert box. But when I use header before alert it's not working. It's redirecting me like it should, but it's not showing any box. Could someone help me?

if ( $pkt < 1 OR $user_id == 0) {
    header("Location: http://dunno.com/file.php");
    $message = 'This is a message.';

echo "<SCRIPT> //not showing me this
alert('$message');
</SCRIPT>";
    mysql_close();
}

这是可行的(但没有标题)

And here's the one which work (but without heading)

if ( $pkt < 1 OR $user_id == 0) {
    $message = 'This is a message.';

echo "<SCRIPT> //showing me
alert('$message');
</SCRIPT>";
    mysql_close();
}

感谢您的帮助:)

@edit也许有任何命令可以使警报等到整个浏览器加载完毕? (如果有问题)

@edit Maybe is there any command to make alert wait until whole browser load? (if it's the problem)

推荐答案

也许尝试使用JavaScript进行重定向.

Maybe try redirect using JavaScript.

if ( $pkt < 1 OR $user_id == 0) {
    $message = 'This is a message.';

    echo "<SCRIPT> //not showing me this
        alert('$message')
        window.location.replace('url of the page');
    </SCRIPT>";
    mysql_close();
}

这篇关于JavaScript警报和php标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆