简体   繁体   English

带有PHP的Javascript-动态调用

[英]Javascript With PHP - Dynamic Calls

I'm new to web development, and I've never created anything too complex before. 我是Web开发的新手,以前从未创建过任何复杂的东西。 By which, I'm implying a complete website, I've usually just cross referenced post/json data with C# or Java. 通过这,我意味着一个完整的网站,我通常只是使用C#或Java交叉引用了post / json数据。 In any case, for a relatively large project, I've been asked to create a user management portal, and cutting more to the point, I'm currently stuck on the login form. 在任何情况下,对于一个相对较大的项目,都要求我创建一个用户管理门户,并且切入正题,我目前仍停留在登录表单上。

I know what to do, and how I'm going to go about managing user data and what not, but I'm trying to understand ajax. 我知道该怎么办,我将如何去管理用户数据,不知道该怎么办,但是我试图理解ajax。 I wanted to slide out a notification for x-failed login attempts, and create a successful login message. 我想滑出X失败的登录尝试通知,并创建成功的登录消息。

I tried to create a popup message to start off using php/js, but my attempt failed. 我试图创建一个弹出消息以使用php / js开始,但尝试失败。 This is essentially what I've got, 这基本上就是我所拥有的,

<?php

    function login() {
        $user = $_POST['user'];
        $pass = $_POST['password'];
        $driver = $_SESSION['driver'];
        if (isset($user) && isset($pass)) {

            if ($driver->login($user, $pass)) {

                echo('<script>window.alert(\'Success\');</script>');
            } else {

                echo('<script>window.alert(\'Failure\');</script>');
            }
        }
    }

?>

I know the login function works just fine, but the alert notification isn't appearing, instead bits of the code appear on the web-page after executed, which shouldn't be occurring seeing as to it's a script-call. 我知道登录功能可以正常工作,但是不会显示警报通知,而是在执行后在网页上显示了一些代码,而这并不是脚本调用。

Any input/insight would be very helpful, and thank you for taking the time to read my thread. 任何输入/见解都将非常有帮助,感谢您抽出宝贵时间阅读我的主题。

而不是将()用于仅使用''这样的回声

echo '<script>alert("Success");</script>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM