我对ajax很新。这是我的javascript:
$(document).ready(function(){
$("#name").autocomplete({
source:'getautocomplete.php',
minLength:1
});
});
这是getautocomplete.php的相关部分
$term=$_GET["name"];
$query=mysql_query("SELECT * FROM stock where itemid like '%".$term."%' order by itemid ");
$json=array();
while($st=mysql_fetch_array($query)){
$json[]=array(
'value'=> $st["itemid"],
'label'=>$st["itemid"]." "
);
}
echo json_encode($json);
我的HTML表单看起来像这样
<input id="name" type="text" class="auto" >
它的作用是加载表的所有元素并列出它,但我只想要与输入文本匹配的结果。必须做出哪些改变
答案 0 :(得分:0)
你应该使用
{$.ajax({url: 'getautocomplete.php',
data:{name: 'passed_name', minLength: 1},
success: function(data){
$("#name2").html(data);
}
}
你没有为$ _GET [“name”]传递你的名字;在你的代码中。