这是屏幕

名为"fetching_book_title_for_barcode.php“的php文件。
<?php
require_once('db.php');
$response=array();
$sql="select book_title from book where barcode_id LIKE '%".$_POST['value']."%'";
$result=mysql_query($sql);
if(mysql_num_rows($result)){
$book_title=mysql_fetch_assoc($result);
$response["book_title1"]=$book_title;
}
echo json_encode($response);
?>下面是带有一些ajax调用的java脚本文件。
var searchTimeout;//Timer to wait a little before fetching the data
$("#barcode_id_textBox").keyup(function() {
var searchKey = this.value;
clearTimeout(searchTimeout);
searchTimeout = setTimeout(function() {
barcodeTextboxFill(searchKey);
}, 400); //If the key isn't pressed 400 ms, we fetch the data
});
function barcodeTextboxFill(searchKey){
$.ajax({
url: 'fetching_book_title_for_barcode.php',
type: 'POST',
dataType: 'json',
data: {value: searchKey},
success: function(data) {
$("#book_title_textBox").val(data);
}
});
}HTML
<input type="text" id="barcode_id_textBox">
<input type="text" id="book_title_textBox">‘我正在根据他们的要求为我的大学制作图书馆管理系统。
在MySql数据库中,我有一个图书表格,我在其中插入了图书记录,其中一列用于条形码id,另一列用于图书标题。
我有一个html页面,上面有两个内联文本框,其中一个是条形码id,另一个是书名。
现在,我希望当输入条形码id时,同时从数据库中获取书名并显示在书名的文本框中。
我试了很久,但没有找到任何解决方案。我通过ajax尝试了一下,但没有得到所需的答案。这里面有什么问题?
每个人的帮助都会被感谢的。提前谢谢。
发布于 2017-01-23 23:18:40
在您的文本框中添加一个类似于<input type="text" id="barcodeTextBox" onChange="BarcodeBoxFill()">的onChange,只要文本框被更改,onChange就会调用JS函数BarcodeBoxFill()。
然后,JS函数应该接受来自框var text = $('#barcodeTextBox').val()的输入
然后,在同一函数上应该有AJAX调用,该调用将文本框的值作为参数传递。然后,在页面中,AJAX调用将是一些SQL,它将为另一个框(在本例中为图书标题)获取正确的值。作为AJAX的success部分,您可以更改other文本框的值,
success: function(data) {
$('#bookTitleTextBox').val(data);
}`https://stackoverflow.com/questions/41804942
复制相似问题