未在php文件中定义的javascript函数

问题描述

我有一个如下所示的PHP代码,其中在Line A的弹出窗口是用按钮OkCancel和消息hello world创建的。

在A行,单击Ok按钮时,我试图在下面的javascript中调用secondUser()函数,然后单击Cancel按钮,我什么都不想发生。

<?PHP
    // ..... some other code

    if (!isset($_SESSION['admin'])) {
        $message = "hello world";
        // create a pop up window with $message on it along with "ok" and "cancel" button
        echo "<script type='text/javascript'>if (confirm('$message')) { secondUser(); };</script>";    // Line A
    }

    // ..... some other code
?>

我想知道如何在单击弹出窗口中的secondUser()按钮时调用Ok函数(如下所示)。我收到错误消息secondUser()函数未定义。

<script>
function secondUser () {
    $.ajax({
        url:"login_second_user.PHP",//the page containing PHP script
        type: "post",//request type,dataType: 'json',data: {registration: "success",name: "xyz",email: "abc@gmail.com"},success:function(result){
            console.log(result.abc);
        }
    });
}
</script>

我所有的PHP和js代码都在文件admin.php中。在小提琴中,我只提到了代码片段,但其中有基本结构。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)