无法使用Jquery分析JSON
Unable to parse JSON using Jquery
我正在尝试使用solr和jquery进行自动建议。为此,我写了以下代码:
$(function(){
$( "#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 中运行时出现以下错误
未捕获的语法错误:意外的标记:我得到的Json数据是这个
{术语:{标题:{答案:24,ansari:5}}
我查阅了以下链接http://jqueryui.com/demos/autocomplete/#remote-jsonp,但我找不到解决方案。请建议我做错了什么
您已经(正确地?)指定了JSONP来访问跨源资源,但您没有告诉Solr您希望它发出JSONP而不是纯JSON。
将jsonp: 'json.wrf'
添加到$.ajax
的参数中。
更多信息,请访问http://xplus3.net/2010/09/21/solr-and-jsonp/
相关文章:
- 正在分析JSON消息中的矩阵
- 分析JSON响应时出现问题
- 如何分析 json 字符串警报
- 如何分析 JSON 对象中的 JSON 字符串
- 在异步读取文件时分析 JSON
- 从文档正文分析 Json
- 分析 JSON 对象以获取列数据
- 正在使用分析Json,但未获取值
- JQuery分析Json文件大小未定义
- 正在分析json数组的流
- 分析Json响应
- 在Ajax中分析Json,错误
- 分析json时出错
- 分析JSON JSON_encoded数据库结果
- 用javascript分析JSON响应
- 无法使用Jquery分析JSON
- AngularJS分析JSON数组对象意外的令牌:
- 正在分析JSON以排除重复的Node.JS
- ";msg":"分析JSON字段值时出错.意外的OBJECT_START
- 无法分析JSON,未捕获语法错误