自动填充文本字段的代码如下:
var ColTags = [
"USA","Canada","China"
];
我需要使用Ajax来填充脚本,但我没有JavaScript经验。
$.ajax({
data: parameter,
url: 'country.php',
type: 'post',
success: function (response) {
var ColTags = [
response
];
$( "#ColTags" ).autocomplete({
source: ColTags
});
}
});
country.php
:
$var="'uno','dos','tres','cuatro'";
echo $var;
答案 0 :(得分:1)
这不是javascript的工作原理。阅读更多相关信息。有很多在线教程可以解释得比我好得多。
$.ajax({
data: parameter,
url: 'country.php',
type: 'post',
success: function (response) {
//error checking is good
if(! (response instanceof Array))
console.log (response);
return false;
}
var colTags = response;
$( "#ColTags" ).autocomplete({
source: colTags
});
}
});
// country.php
$var=array('uno','dos','tres','cuatro');
echo json_encode($var);