Php jQuery自动完成跨站点域-不显示列表框
我想使用外部数据自动完成。我遵循手册,数据顺利返回,但列表框不显示。有人能帮我吗 这是我的js:Php jQuery自动完成跨站点域-不显示列表框,php,jquery,json,autocomplete,cross-domain,Php,Jquery,Json,Autocomplete,Cross Domain,我想使用外部数据自动完成。我遵循手册,数据顺利返回,但列表框不显示。有人能帮我吗 这是我的js: $('.hledejNACE').autocomplete({ source: function( request, response ) { $.ajax({ url: "ac.php", dataType: "jsonp", data: {term: request.term},
$('.hledejNACE').autocomplete({
source: function( request, response ) {
$.ajax({
url: "ac.php",
dataType: "jsonp",
data: {term: request.term},
success: function( data ) { response( data ); }
});
},
minLength:1,
select:function(evt, ui) {
// when a name is selected, populate related fields in this form
this.form.kodNACE.value = ui.item.kodNACE;
}
});
Mozilla开发工具说,数据以JSON格式成功返回
这是我的html:
<form onsubmit="return false;">
Name: <input id="hledejNACE" type="text" class="hledejNACE" style="width:250px;"/>
Code: <input id="kodNACE" type="text" disabled />
</form>
姓名:
代码:
我链接了以下脚本:
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
我找到了一个解决方案: 您需要在PHP json返回中使用回调:
<?php
$data = '{}'; // json string
if(array_key_exists('callback', $_GET)){
header('Content-Type: text/javascript; charset=utf8');
header('Access-Control-Allow-Origin: http://www.example.com/');
header('Access-Control-Max-Age: 3628800');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
$callback = $_GET['callback'];
echo $callback.'('.$data.');';
}else{
// normal JSON string
header('Content-Type: application/json; charset=utf8');
echo $data;
}
?>
谢谢大家的努力 如果你们能给我你们测试服务器的链接,也许我可以帮你们。它返回
json
或jsonp
?在Chrome、Opera和Internet Explorer上可以正常工作,但我没有看到包含返回值的列表框…嗯。。。它适用于任何东西,但不适用于FireFox。。。这很奇怪jQuery中似乎有错误<代码>语法错误:'*,:x'在jquery-1.10.2.js
line1639
中不是有效的选择器。。。