gpt4 book ai didi

javascript - 无法让 ajax 显示在页面中,但可以在谷歌元素检查器中看到

转载 作者:行者123 更新时间:2023-11-29 00:11:17 25 4
gpt4 key购买 nike

我正在制作一个简单的发票页面。我从 mysql 填充一个下拉框,当我检查该项目时,我希望预填充描述框。但它不起作用......我可以在 chrome 的网络检查器中看到它并预览它。我的代码如下 htmlinputform, php, ajaxget

<div class="row">

<div class="col-md-2">
<select type="text" name='idd' id="inputItem" placeholder="Item #1" class="form-control" onblur="showUser(this.value)">
<option></option>
<?php

require ('dbconnect.php');
$result = $con->query("select id, item from items");

while ($row = $result->fetch_assoc()) {

unset($id, $name);
$id = $row['id'];
$name = $row['item'];
echo '<option value="'.$id.'">'.$name.'</option>';

}
echo "</select>";
mysqli_close($con);
?>

</div>
<div class="col-md-6">
<input type="text" id="description1" placeholder="Description" class="form-control" onchange="1description()"></div>
<div class="col-md-1">
<input type="text" id="qty1" placeholder="Qty." class="form-control"></div>
<div class="col-md-1">
<input type="text" id="tax1" placeholder="Tax" class="form-control"></div>
<div class="col-md-2">
<input type="text" id="itemprice1" placeholder="Item Total" class="form-control" onchange="myFunction()" onblur="myFunction1()"></div>
</div>

PHP

<?php
$q = intval($_GET['q']);
require ('dbconnect.php');
mysqli_select_db($con,"items");
$sql="SELECT description FROM items WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);



while($row = mysqli_fetch_array($result)) {


echo $row['description'];

}


mysqli_close($con);
?>

Ajax

<script>
function showUser(str) {
if (str=="") {
document.getElementById("description1").innerHTML="";
return;
}
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 (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("description1").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>

最佳答案

使用 .value 而不是 innerHTMLinnerHTML 不用于输入字段。

document.getElementById("description1").value =xmlhttp.responseText

关于javascript - 无法让 ajax 显示在页面中,但可以在谷歌元素检查器中看到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24899832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com