对于这种情况,我找不到任何解决方案,当 id 用户文本值更改时,名称和地址将被填充。但它在 php 查询中返回了一些错误。
抱歉,如果这篇文章重复,因为我找不到适合我的情况的解决方案。
这里是html表单
<form id="frm_add_bill" name="frm_add_bill" >
<label >id user</label>
<input type="text" onchange="getplg()" id="kdp" name="kdp">
<label >user name</label>
<input type="text" maxlength="25" name="name" id="name" readonly>
<label >user address</label>
<input type="text" name="address" id="address" readonly>
</form>
这里是javascript和php代码
<script type="text/javascript"> function getplg(){
var kdpe = $('#kdp').value;
$.ajax({
type: 'post',
url: '',
data: kdpe,
timeout: 50000
});
}</script>
<?php
if (isset($_POST['kdpe'])) {
$kpde=htmlspecialchars($_POST['kdpe']);
$amxz=mysql_query("SELECT name, address from tbl_user where id_user='$kpde'");
$camqz=mysql_fetch_array($amxz);
echo "<script>document.write(fillem());</script>";
}
?>
<script type="text/javascript">
function fillem(){
document.frm_add_bill.name.value=<?php echo $camqz['0'];?>;
document.frm_add_bill.address.value=<?php echo $camqz['1'];?>;
}
</script>
最佳答案
function getplg(){
try{
var kdpe = $('#kdp').val();
console.log("here");
$.ajax({
method: 'post',
url: '',
data: {val:kdpe}}).done(function(data){
console.log(data);
console.log("hello");
});
}catch(Exception){
alert("error");
}
}
</script>
试试这个。
关于javascript - 使用javascript var通过php mysql查询数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35667211/