很简单的事。
使用$.getJSON,并且在jquery函数中捕获被调用的.php文件的响应。json编码的php数组是一个关联数组。
$.getJSON("file.php",function(response){
// print the associative response array in var_dump or print_r fasion
});
file.php包含:
<?php
$my_array=array();
//$my_array['random_index1']="random_value1";
//$my_array['random_index2']="random_value2";
//$my_array['random_index3']="random_value3";
// and so on
echo json_encode($my_array);
?>
$my_array有随机键和值。
如何打印整个“响应”数组,就像php中的print_r方式一样?
EDIT1:,我想把它打印在网页或警告框中。并不是说我只想查看javascript控制台中的值(chrome,FF或其他什么)。
EDIT2:如果我将$.getJSON的主体写成如下:为什么不能工作:
for(var i in response){
console.log("i="+i+" content="+response[i]);
}
发布于 2014-09-16 08:38:25
我相信console.dir()
是你要找的东西:
https://developer.mozilla.org/en-US/docs/Web/API/Console.dir
唯一的缺点是它不允许标记输出的每个对象,而且它也是一个非标准的控制台方法。
发布于 2012-02-08 04:48:05
使用类似于Doug的JSON图书馆将响应转换为文本并用console.log
记录它
function(response) {
console.log(JSON.stringify(response));
}
https://stackoverflow.com/questions/9192990
复制相似问题