[英]jQuery Autocomplete using AJAX didn't work
我試圖使用AJAX方法創建自動完成功能,但沒有成功。 我在AJAX成功和自動完成源功能中添加了警報,以查看問題出在哪里,源的警報起作用。 我找不到AJAX問題,下面是代碼:
jQuery的:
$("#wopartname").autocomplete({
source:function(request,response){
$.ajax({
url:AjaxWO,
dataType: "json",
data: {
"act":"selectPartName",
"name":request.term
},
success: function(data) {
response(data);
alert("AJAX");
}
});
alert("SOURCE");
},
minLength:3
});
PHP:
function selectPartName(){
$name = $_POST['name'];
$query = "SELECT nama FROM sparepart WHERE nama LIKE '%$name%' ORDER BY nama ASC";
$result = mysql_query($query);
if($result){
while($fetch = mysql_fetch_array($result)){
$data[] = array('label' => $fetch['nama'],'value' => $fetch['nama']);
}
echo json_encode($data);
}else{
echo "KO";
}
}
謝謝。
我將AJAX類型聲明為“ POST”,並且可以正常工作。
$("#wopartname").autocomplete({
source:function(request,response){
$.ajax({
url:AjaxWO,
type:"POST",//<===
dataType: "json",
data: {
"act":"selectPartName",
"name":request.term
},
success: function(data) {
response(data);
}
});
},
minLength:3
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.