我正在尝试使用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