3
$("#ethnicbg").autocomplete({
source: function(request, response) {
$.ajax({
url: 'ethnic/',
type: 'POST',
dataType: "jsonp",
data: {
q: request.term
},
success: function(data) {
response($.map(data, function(item) {
return {
label: item.title,
value: item.value
}
}));
}
});
},
minLength: 1,
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");
}
});
PHP
header('Content-type: application/json');
$url = $this->url->get();
$arr = get_data(); // returns [{"title":"White","value":"White"}]
echo json_encode($arr);
它返回的数据,问题是某处的成功:函数, 只是response($.map....
我的推杆console.log('TEST')
DNT似乎之前去那里,或者提醒任何我做错了什么?
解决
dataType: "jsonp",
应该dataType: "json",
如果什么都可以有人解释JSON,JSONP之间的区别?在这种情况下,它可以帮助我和其他人可能会遇到问题?
JSONP允许您向与请求页面不同的域中的服务器发出请求:http://en.wikipedia.org/wiki/JSONP – 2011-04-19 14:37:53