//this script returns a json array for use in jquery autocomplete fields for site lists... header('Content-type: application/json'); require("connect.php");
$client_id = $_GET['?'];
//do the query for sites that are active $sql = "SELECT * FROM site WHERE active=1 AND client_id='$client_id' ORDER BY site_name ASC"; $result = mysql_query($sql) or die('Error: ' . mysql_error());
//loop the results and create php array while($row = mysql_fetch_array($result)){ $arr[] = array('label' => $row['site_name'], 'value' => $row['id']); }
echo json_encode($arr);
câu trả lời hay nhất
最终编写了我自己的解决方案并废弃了该插件。享受。
//dynamically returns the sites once the user chooses a client - edit/add shift form $('.client-id').change(function () { var selectedClient = $(this).val(); if (selectedClient != null && selectedClient != '') {
$.getJSON('returnSiteList.php', { id: selectedClient }, function (Sites) { var siteSelect = $('.site-id'); siteSelect.empty(); $.each(Sites, function (index, site) { siteSelect.append($('', { value: site.value, text: site.label })); }); }); } });
Tôi là một lập trình viên xuất sắc, rất giỏi!