我正在使用jquery aucomplete
https://github.com/devbridge/jQuery-Autocomplete/
但
它适用于local
并在使用时产生问题server side script
错误图片
我的代码就像
HTML
<div>
<input type="text" name="country" id="autocomplete"/>
</div>
<div id="selection"></div>
CSS
.autocomplete-suggestions { border: 1px solid #999; background: #FFF; cursor: default; overflow: auto; }
.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
.autocomplete-selected { background: #F0F0F0; }
.autocomplete-suggestions strong { font-weight: normal; color: #3399FF; }
脚本
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="jquery.autocomplete.js"></script>
<!-- Above js file can be downloaded from
https://github.com/devbridge/jQuery-Autocomplete/blob/master/src/jquery.autocomplete.js
-->
<script type="text/javascript">
$('#autocomplete').autocomplete({
serviceUrl: 'search.php',
onSelect: function(suggestion) {
$('#selction-ajax').html('You selected: ' + suggestion.value + ', ' + suggestion.data);
}
});
</script>
PHP 页面脚本 search.php
<?php
if($_REQUEST['query']=='a')
{
echo json_encode(array('AD'=>'Adrew','AU'=>'Australia'));
}
if($_REQUEST['query']=='b')
{
echo json_encode(array('BR'=>'Brazil','BA'=>'Bangladesh'));
}
if($_REQUEST['query']=='i')
{
echo json_encode(array('IN'=>'India','IND'=>'Indonasia'));
}
return;
?>
感谢您的任何建议。