jquery 自动完成让我头疼。输入 textbox 后,自动完成代码不返回数据。我似乎可以在代码中找到问题所在。
$().ready(function() {
$("#msg_to").autocomplete({
source:"new_temp.php",
width: 260,
matchContains: true,
selectFirst: false
});
});
我的PHP代码是:
require('mysql_connect.php');
$word = $_REQUEST['term'];
$s_query = "
SELECT user_id , full_names , userName FROM elib_users
WHERE full_names LIKE '%".$word."%' || userName LIKE '%".$word."%' limit 1";
$sql = mysql_query($s_query) or die(mysql_error());
$count = mysql_num_rows($sql);
if($count > 0){
while($row = mysql_fetch_array($sql)){
$to_name = $row['full_names'];
$to_id = $row['user_id'];
$to_usName = $row['userName'];
$data[] = array('label' => $to_name = $row['full_names']);
}
}
echo json_encode($data);
html文本输入
<input type="text" name="msg_to" class="btn" id="msg_to" />