Javascript Ajax错误:不返回数据库值
我的ajax php编码有问题。 问题是当用户输入密码登录时,live Check功能输出仅在下面的选择框中显示为空,而不是数据库中的数据。 下面是我的代码: Login.phpJavascript Ajax错误:不返回数据库值,javascript,php,html,ajax,Javascript,Php,Html,Ajax,我的ajax php编码有问题。 问题是当用户输入密码登录时,live Check功能输出仅在下面的选择框中显示为空,而不是数据库中的数据。 下面是我的代码: Login.php username:<input type="text" class="name" id="uname" placeholder="enter your username here"><br> password:<input type="password" class="pass" id="
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>
用户名:
密码:
责任:
选择你的责任
函数showUser(str){
如果(str==“”){
document.getElementById(“txt”).innerHTML=“”;
返回;
}否则{
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}否则{
//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“txt”).innerHTML=this.responseText;
}
};
open(“POST”,“dblogin.php?q=“+str,true”);
xmlhttp.send();
}
}
document.getElementById('pword')。addEventListener(“键控”,函数(str){
showUser(str);
},假);
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
<?
}
?>
xmlhttp.send()代码>-您没有发送任何post数据-您可以更改获取的方法,并且$q=intval($\u GET[“q”])代码>xmlhttp.send()代码>-您没有发送任何post数据-您可以更改获取的方法,并且$q=intval($\u GET[“q”])代码>
<?
$host="localhost";
$db="logindb"
$user="root"
$pass="";
?>