jQuery UI自动完成jsonp映射响应
问题描述:
我想从jqueryUI使用自动完成。当我提醒我的回应我得到以下内容:([ { "id": "test", "label": "test", "value": "test" } ]);
jQuery UI自动完成jsonp映射响应
但当我尝试映射结果下拉结果为空。这里是我的代码:
<script>
$(function() {
function log(message) {
$("<div/>").text(message).prependTo("#log");
$("#log").scrollTop(0);
}
$("#city").autocomplete({
source: function(request, response) {
$.ajax({
url: "http://localhost/jQuery/development-bundle/demos/autocomplete/search3.php",
jsonp: "jsonp_callback",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term
},
success: function(data) {
alert(data);
response($.map(data, function(item) {
return {
label: item.label,
value: item.value
}
}));
}
});
},
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");
}
});
});
</script>
我的服务器端脚本使用下面的代码:
echo $_GET['jsonp_callback'] . '(' . $data . ');';
还是要谢谢你
答
使用此行
url: "http://ws.geonames.org/searchJSON?jsonp_callback=?",
和数据类型也
dataType: 'jsonp',
代替
url: "http://ws.geonames.org/searchJSON",
我的错抄错码我用这个网址有我的脚本位于该得到的数据,并使用回声$ _GET [“jsonp_callback”]。 '('。$ data。');';我使用这个网址http://localhost/jQuery/development-bundle/demos/autocomplete/search3.php – 2012-04-16 10:21:24
我改变了网址为:http://localhost/jQuery/development-bundle/demos/autocomplete/search3.php ?jsonp_callback =? 现在是我的回应:?([{“id”:“Jimmy”,“label”:“Jimmy”,“value”:“Jimmy”}]); 但仍下拉为空 – 2012-04-16 10:24:56
检查我更新的答案 – 2012-04-16 10:28:51