Ajax错误:不返回数据库值

时间:2017-03-22 04:14:25

标签: javascript php html ajax

我的ajax php编码有问题。 问题是当用户输入他们的密码登录时,实时检查功能输出只在下面的选择框中显示为空白,而不是来自数据库的数据。 以下是我的代码:

的login.php

username:<input type="text" class="name" id="uname" placeholder="enter your username here"><br>
password:<input type="password" class="pass" id="pword" placeholder="password here"><br>
<div id="txt">
   responsibility:<select id="opti">
        <option value=""> Select your responsibility</option>
</select><br></div>


<script>
function showUser(str) {
   if (str == "") {
    document.getElementById("txt").innerHTML = "";
    return;
} else {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("txt").innerHTML = this.responseText;
        }
    };
    xmlhttp.open("POST","dblogin.php?q="+str,true);
    xmlhttp.send();
   }
}
document.getElementById('pword').addEventListener("keyup", function(str) {
    showUser(str);
}, false);
</script>

Dblogin.php

<?
$q=intval($_POST["pword"]);

require ("config.php");
$link=mysqli_connect($host,$user,$pass,$db);

$query="select responsibility from testing where password = '".$q."'";
$result=mysqli_query($link,$query);
    if($result){
?>
<form>
responsibility:<select id="opti">
<?
    while($row=mysqli_fetch_array($result))
    echo"<option value='$row[1]'>$row[1]</option>";
?>
</select>
<input type=submit value ="submit">
<?
}
else
{
?>
Error:No Data Found
<?
}
?>

的config.php

<?
   $host="localhost";
   $db="logindb"
   $user="root"
   $pass="";
?>

ajax函数是可行的,但数据库数据未显示。任何人都能告诉我编码有什么问题。

0 个答案:

没有答案