【发布时间】:2015-08-23 03:48:58
【问题描述】:
我尝试从服务器响应 json,例如 the official demo。
但是没有显示下拉建议。
谁能告诉我我错过了什么? 我只更改了演示代码中的 url:
{
label: 'Ship Name2',
name: 'ShipName2',
width: 150,
editable: true,
edittype: "text",
editoptions: {
dataInit: function (element) {
$(element).attr("autocomplete","off").typeahead({
appendTo : "body",
source: function(query, proxy) {
$.ajax({
url: 'mysite',
dataType: "jsonp",
data: {term: query},
success : proxy
});
}
});
}
}
}, {
label: 'Ship Name',
name: 'ShipName',
width: 150,
editable: true,
edittype: "text",
editoptions: {
dataInit: function (element) {
$(element).attr("autocomplete","off").typeahead({
appendTo : "body",
source: function(query, proxy) {
$.ajax({
url: 'http://trirand.com/blog/phpjqgrid/examples/jsonp/autocompletepbs.php?callback=?&acelem=ShipName',
dataType: "jsonp",
data: {term: query},
success : proxy
});
}
});
}
}
}
附:我的 servlet 返回与 demo 完全相同的 json。
谢谢!!
编辑1:如果我想在这个演示中使用预输入,响应不应该只是一个json吗?
如果我在演示中执行url,我会得到以下 javascript 而不是 json:
<script type='text/javascript'>
jQuery(document).ready(function() {
if(jQuery.ui) {
if(jQuery.ui.autocomplete){
jQuery('ShipName').autocomplete({
"appendTo":"body",
"disabled":false,
"delay":300,
"minLength":1,
"source":function (request, response){
request.acelem = 'ShipName';
request.oper = 'autocmpl';
$.ajax({
url: "autocompletep.php",
dataType: "json",
data: request,
type: "GET",
error: function(res, status) {
alert(res.status+" : "+res.statusText+". Status: "+status);
},
success: function( data ) {
response( data );
}
});
}});
jQuery('ShipName').autocomplete('widget').css('font-size','11px');
jQuery('ShipName').autocomplete('widget').css('z-index','1000');
}
}
});
</script>
谁能告诉我为什么?
【问题讨论】: