Php 使用ajax创建身份验证应用程序,但没有返回

Php 使用ajax创建身份验证应用程序,但没有返回,php,jquery,Php,Jquery,当我点击post时,我从firefox得到的post响应是:(当我输入k作为用户名时) 密码 用户名k 来源:username=k和password= 从php接收的打印不会显示在#errorshow div中 这是我的密码 (html) $(函数(){ $(“#登录表单”).submit(函数(){ var uname=$(“#用户名”).val(); var upass=$(“#密码”).val(); $.post(“auth.php”,{username:uname,password:u

当我点击post时,我从firefox得到的post响应是:(当我输入k作为用户名时)

密码 用户名k

来源:username=k和password=

从php接收的打印不会显示在#errorshow div中

这是我的密码 (html)


$(函数(){
$(“#登录表单”).submit(函数(){
var uname=$(“#用户名”).val();
var upass=$(“#密码”).val();
$.post(“auth.php”,{username:uname,password:upass},函数(数据){
$(“#errorshow”).html(数据);
});
返回false;
});
});
用户名:

密码:

下面是php(auth.php)


尝试更改行:

$(function() {

由于您的脚本试图将“submit”方法绑定到一个不存在的表单(直到页面加载为止)

我一直认为$(function()和$(document)。ready也有同样的目的,而$(function)只是一个简短的符号。现在我明白了,非常感谢!
<?php
mysql_connect("","","") or die(mysql_error());
mysql_select_db("") or die(mysql_error());

$username = $_POST['username'];
$password = $_POST['password'];



$query = mysql_query("select username,password,active,role from tbl_logins where username = '$username'") or die(mysql_error());
 while($row = mysql_fetch_assoc($query)) {

 // CHECK FOR EMPTY FIELDS
    if(empty($username) || empty($password)) {
    print "the username or password is empty";
    }




    //CHECK FOR USERNAME EXISTANCE
    elseif($db->num_rows($query) == 0) {
 print "the username you entered doesnt exist";
 }


    //CHECK FOR PASSWORD IS CORRECT
    elseif(sha1($password) != $row['password']) {
 print "the password you entered is incorrect";
 }


     //CHECK IF ACCOUNT IS ACTIVE
     elseif($row['active'] == 'no') {
     print "your account is not active. please verify your email";
  }


 else {

 //create cookie and login user.

 $_SESSION['AUTHID'] = sha1($row['hash']);

 //routh to appropriate role section
 if($row['role'] == "0") {
 $_SESSION['error'] = "";
 header("Location: /_admin/dashboard.php");
 } else {
 $_SESSION['error'] = "";
 header("Location: /worldex/_members/index.php");
 }

 }//end else


 } //end while


?>
$(function() {
$(document).ready(function() {