Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ajax-don';注册期间不显示验证消息_Ajax_Jquery - Fatal编程技术网

Ajax-don';注册期间不显示验证消息

Ajax-don';注册期间不显示验证消息,ajax,jquery,Ajax,Jquery,我试图做的是在尝试注册时显示用户名或电子邮件存在时的验证消息。我使用了json_encode,它有消息和状态。所发生的事情是,当我键入一个用户名和一封存在的电子邮件时,它不会做任何事情,也不会显示消息或注册 if($_SERVER["REQUEST_METHOD"] == "POST") { if($_POST["password"] !== $_POST["confirmation"]) { echo json_encode(array('msg'=>"pa

我试图做的是在尝试注册时显示用户名或电子邮件存在时的验证消息。我使用了json_encode,它有消息和状态。所发生的事情是,当我键入一个用户名和一封存在的电子邮件时,它不会做任何事情,也不会显示消息或注册

if($_SERVER["REQUEST_METHOD"] == "POST")
{
    if($_POST["password"] !== $_POST["confirmation"])
    {
       echo json_encode(array('msg'=>"password and confirmation aren't equal.", 'url'=>"", 'status'=>false));  
    }
    else if(($data['username']=== $_POST['username'] )|| ($data['email'] === $_POST['email'] ))
    {
        echo json_encode(array('msg'=>"Username or  email exists.", 'url'=>"", 'status'=>false));    
    }
    else
    {
    $result = query("INSERT INTO users (username, hash, email) VALUES (?,?,?)", $_POST["username"], crypt($_POST["password"]), $_POST["email"]); 
        $rows = query("SELECT LAST_INSERT_ID() AS id");
        $id = $rows[0]["id"];  
        $_SESSION["id"] = $id;   
        echo json_encode(array('msg'=>"Success.", 'url'=>"/kinema/html/index.php", 'status'=>true));        
    }
}
scripts.js

$('#register_form').on('submit', function(e) {
        e.preventDefault(); 

        var name = $('#register_form input[name=username]').val();
        var email = $('#register_form input[name=email]').val();

            $.ajax({
                  url: "register.php",
                  type: "POST",
                  data: {
                         username: name,
                         email: email
                        },
                  dataType: 'json',
                  success: function(response) {          
                    if(response.status){  
                    console.log(response);
                    window.location = response.url;
                    }
                    else
                    {
                        $('#invalid_register').html(response.msg);  
                    }
                }
            });
    });

您没有发布密码或确认值,这将引发未定义的索引错误

据我所知,$data数组不存在,或者您发布的代码不完整