我正在嘗試使用solr和jquery一起進行自動建議。爲此,我寫了下面的代碼:意外的令牌: JSON數據我無法使用jquery解析JSON
$(函數(){
$("#artist").autocomplete({
source: function(request, response) {
$.ajax({
url: 'http://localhost:8983/solr/terms?terms.fl=heading&terms.prefix='
+request.term+'&wt=json&json.nl=map',
dataType: "jsonp",
data: {
q: request.term,
rows: 10,
omitHeader: true,
},
success: function(data) {
response($.map(data.terms.heading, function(item) {
return {
label: item,
value: item
}
}
)
);
}
});
},
minLength: 2,
select: function(event, ui) {
log(ui.item ?
"Selected: " + ui.item.label :
"Nothing selected, input was " + this.value);
},
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
});
我收到以下錯誤在Chrome
未捕獲的SyntaxError運行時我得到的是這種
{ 「條款」:{ 「標題」:{ 「答案」:24, 「安薩里」:5}}}
我諮詢下面的鏈接http://jqueryui.com/demos/autocomplete/#remote-jsonp但我無法找到解決方案。請建議我做錯了什麼
您發佈的代碼有錯誤的「});」最後。也應該dataType:不是「json」而不是「jsonp」; – CBusBus 2012-01-18 08:15:43
可能試試$ .map(data.d.terms.heading,函數(item) – 2012-01-18 08:18:03
可以發佈jQuery字符串嗎? – 2012-01-18 08:39:07