如何使用 ajax 调用 name onkey up?
how to call name onkey up using ajax?
我是 ajax 的新手。我想根据 onkey up 从数据库中获取名称,但我在控制台 "Invalid left-hand side in assignment" 中收到此错误。当我输入它时显示 "showname function is not defined".?
这是我的代码。
搜索:
This is myscript
function showname(d) {
var xhttp;
if (window.XMLHttpRequest) {
xhttp= new XMLHttpRequest();
}else{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("POST", "ajax2.php?name"=+d, true);
xhttp.send();
}
this ajax2.php code
$name = $_GET["name"];
$db = new mysqli("localhost", "root", "", "customername");
$conn = $db->query("select customerName from customers like '".$name."%'");
$fetch = $conn->fetch_array();
?>
<?php foreach ($fetch as $key => $value) :?>
<p><?php echo $value ?></p>
<?php endforeach; ?>
提前致谢。
xhttp.open("POST", "ajax2.php?name"=+d, 真);
我想你打错了,把 = 放在引号里。
xhttp.open("POST", "ajax2.php?name=" + d, true);
我是 ajax 的新手。我想根据 onkey up 从数据库中获取名称,但我在控制台 "Invalid left-hand side in assignment" 中收到此错误。当我输入它时显示 "showname function is not defined".? 这是我的代码。 搜索:
This is myscript
function showname(d) {
var xhttp;
if (window.XMLHttpRequest) {
xhttp= new XMLHttpRequest();
}else{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("POST", "ajax2.php?name"=+d, true);
xhttp.send();
}
this ajax2.php code
$name = $_GET["name"];
$db = new mysqli("localhost", "root", "", "customername");
$conn = $db->query("select customerName from customers like '".$name."%'");
$fetch = $conn->fetch_array();
?>
<?php foreach ($fetch as $key => $value) :?>
<p><?php echo $value ?></p>
<?php endforeach; ?>
提前致谢。
xhttp.open("POST", "ajax2.php?name"=+d, 真);
我想你打错了,把 = 放在引号里。
xhttp.open("POST", "ajax2.php?name=" + d, true);