我需要从MySQL数据库中获取数据并将其放入JSON数组中,然后使用该JSON数组进行文本框自动完成。我可以使用单独的PHP文件从数据库中加载数据并在ajax中使用它来实现这一点...... 但是我正在尝试使用一个PHP文件来完成此操作...... 这可能吗?如何操作。
<script>
$(document).on('keyup','.jornal', function(){
var thisRow = $(this).data('value');
if(event.which != 13){
//itemSearchDisables(thisRow);
}
autoTypeNo2=1 ;
autoTypeNo1=0 ;
$(this).autocomplete({
source: function( request, response ) {
$.ajax({
url : 'AJAX_Requst/bill_itemDetail.php',
dataType: "json",
method: 'post',
data: {
ID: request.term
},
success: function( data ) {
response( $.map( data, function( item ) {
var code = item.split("|");
if(code[0] == 'Login Please'){
//window.location = '../login.php';
}
return {
label: code[autoTypeNo2] + ' | '+ code[3],
value: code[autoTypeNo1],
data : item
}
}));
}
});
},
autoFocus: true,
minLength: 0,
select: function( event, ui ) {
var names = ui.item.data.split("|");
id_arr = $(this).attr('id');
id = id_arr.split("_");
//itemSearchEnables(thisRow);
$('#itemNo_'+id[1]).val(names[0]);
$('#itemName_'+id[1]).text(names[1]);
}
});
});
</script>
这是我现在已经做的加载数据工作,目前一切正常。