关注http://phpseason.wordpress.com/2013/02/13/php-autocomplete-tutorial-using-jquery/ 我写了这段代码:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
<script>
jQuery(document).ready(function() {
jQuery("#member").on('input',function(e){
var member = jQuery("#member").val();
// alert(member);
jQuery.ajax({
type:"POST",
url:"<?=bloginfo('url')?>/wp-content/themes/hades/process_data_db.php",
data:{getmember:member},
success:function(data){
//jQuery("#member").val(data.member);
//alert(data);
jQuery("#member").autocomplete({
source:data,
minLength:1});
}
});
});
});
</script>
从php代码文件中获取json数据,然后自动完成名为member
的表单的文本框。现在这段代码工作正常。它重新调整了这个Json数据:
[{"value":"NameA,IND"},{"value":"NameB,BNP-A"},}]
但它无法调用自动完成功能将值绑定到文本框。
答案 0 :(得分:1)
jQuery("#member").on('input',function(e){
var thiselem=$(this);
var member = jQuery("#member").val();
// alert(member);
jQuery.ajax({
type:"POST",
url:"<?=bloginfo('url')?>/wp-content/themes/hades/process_data_db.php",
data:{getmember:member},
success:function(data){
//jQuery("#member").val(data.member);
//alert(data);
thiselem.autocomplete({
source:data,
minLength:1});
}
});