我正在尝试通过从一个字段中选择来创建与自动填充相关的字段。喜欢..选择公司名称&自动填写其描述,编号。我不知道jquery我看起来很少但没有找到或理解。
if (isset($_GET['type']) && $_GET['type']){
$company = array();
try {
$statC = $db->prepare('SELECT CompanyID, CompanyName, CompanyNumber, CompanyDescription FROM Company');
$statC->execute(array('type' => '%'.$_GET['type'].'%'));
while($row = $statC->fetch()) {
$company[] = $row['CompanyName'];
$company[] = $row['CompanyID'];
$company[] = $row['CompanyNumber'];
$company[] = $row['CompanyDescription'];
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo json_encode($company);
}
我的jquery自动完成工作正常但在一个输入字段中显示所有结果
$(function() {
//autocomplete Day
$(".companyid").autocomplete({
source: "company.php",
minLength: 1
});
});
我应该在php中制作单独的数组吗?像
$comName = array();
$comID = array();
$comDes = array();
$comNum = array();
答案 0 :(得分:0)
jquery UI自动填充功能用于在键入google do时显示建议。你可以
var type = 'Your type goes here';
$.getJSON( "ajax/test.json?type=" + type, function( data ) {
//data will be a json object of following structure
//{"CompanyName":"CompanyName", "CompanyID":"CompanyID", "CompanyNumber":"CompanyNumber", "CompanyDescription":"CompanyDescription"}
//
})