更新时间:2022-02-21 23:31:03
使用 json_en code()
来转换PHP关联数组到JSON,并使用 $。的getJSON()
,它会返回一个JavaScript数组。
Use json_encode()
to convert an associative array from PHP into JSON and use $.getJSON()
, which will return a Javascript array.
例如:
<?php echo json_encode(array("a" => "valueA", "b" => "valueB")); ?>
在JavaScript的:
In Javascript:
$.getJSON("myscript.php", function(data) {
alert("Value for 'a': " + data.a + "\nValue for 'b': " + data.b);
});