jquery读取php数组

时间:2017-12-09 18:49:57

标签: php arrays json

我试图改变一个var来获取和卡住

这就是我所做的:

var choices = [['Australia', 'au'], ['Austria', 'at'], ['Brasil', 'br']];

所以这是有效的,我想在

上更改它
$.getJSON('/modules/profile/readCountry.php',function(data){
    arrays = data;
});
var choices = arrays;

但无效

php文件是:

foreach($countryies as $countr => $countrv) {
    $json[] = array($countrv,$countr);
}
header("Content-type:application/json"); 
$out = array_values($json);
echo json_encode($out);

,输出为:

[['Australia', 'au'], ['Austria', 'at'], ['Brasil', 'br']]

如何清除缺少或不起作用的内容?

1 个答案:

答案 0 :(得分:0)

$。getJSON是异步调用

    var choices = [];
    $.getJSON('/modules/profile/readCountry.php',function(data){
        choices = data;
        // do something with array
    });