Thinkphp : $this -> the_ipsort = json_encode(M($this -> ipsort) -> getField('name',true)) ;
php文件:echo json_encode($arr);
ajax接收:var ret=eval("("+xmlhttp.responseText+")");
非ajax接收:<script>var citys=eval(<?php echo json_encode($citys) ?>);</script>
引用:ret[row]['name'];
jquery ui 有一个自动完成的功能,但里面需要使用一个数据格式为
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
使用上面的方式就可以生成 [xxxx]每个值都会有引号
function autoipsort()
{
var availableTags = eval({$the_ipsort}) ;
$( "#sort" )
// don't navigate away from the field on tab when selecting an item
.bind( "keydown", function( event ) {
if ( event.keyCode === $.ui.keyCode.TAB &&
$( this ).data( "autocomplete" ).menu.active ) {
event.preventDefault();
}
})
.autocomplete({
minLength: 0,
source: availableTags
});
}