我正在尝试使用 json_encode 将数组从 PHP 传递到 javascript
但是当我提醒这些值时,我只看到“对象对象等”
当我 var_dump 它时,我看到了实际的数组,但它没有在警报中显示它们
任何帮助,将不胜感激
问候
这是 var_dump
array(1) {
[0]=>
array(2) {
["id"]=>
string(19) "3.0268"
["postcode"]=>
string(137) "hello"
}
}
array(2) {
[0]=>
array(2) {
["id"]=>
string(19) "3.0268070455319E+17"
["postcode"]=>
string(137) "ECMWF continues its flip-flopping, still a temp drop next week & #snow risk but then no rise, http://t.co/tBlg9Ihs #ukweather #uksnow"
} 代码
<?php
$con = mysql_connect('localhost', 'root', '');
mysql_select_db('test');
$result = mysql_query("SELECT * FROM address");
$arr = array();
while($row = mysql_fetch_assoc($result)) {
$arr[] = $row;
}
?>
<script>
var test = <?php echo json_encode($arr); ?>;
alert(test);
</script>