我有問題讓這個JQuery AJAX顯示在網頁上。JQuery自動完成在頁面上沒有顯示
$(document).ready(function(e) {
$(".autocomp").autocomplete(
{
source: function(request, response) {
$.ajax({
url: "/apples",
dataType: "json",
data: {
srch:request.term
},
success: function(data) {
response($.map(data.result, function(item) {
return {
label: item.name,
value: item.name,
data: item
};
}));
}
});
},
minLength: 2,
select: function(event, ui){
var parts = this.name.match(/(\D+)(\d+)$/);
$("key_"+parts[2]).val(ui.item.data.key);
}
});
});
該函數調用返回信息的網站:{result: [{name:macintosh,key:1},{name:golden,key:2},{name:fuji,key:3}]}
。 數據字段發送回的對象是:
Object {result= [Object{name:macintosh,key:1},Object{name:golden,key:2},Object{name:fuji,key:3}]}
的HTML:
<input type="text" name="name_1" id="name_1" class="autocomp"><input type="hidden" name="key_1" id="key_1">
任何人有一個想法,爲什麼它不工作?我進口
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.min.js"></script>
和樣式表:
<link href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
任何幫助將不勝感激!
你丟失了'HTTP:'你在哪裏鏈接的jQuery – 2013-03-24 23:06:21
它應該是'' – 2013-03-24 23:06:53
您能否顯示打到」/ apples「端點時返回的內容? – 2013-03-24 23:10:20