【发布时间】:2015-09-12 15:19:18
【问题描述】:
好的,我有一个 txt 文件。
我把txt文件的数据变成一个数组。
$lines = file($filename);
然后将数据发送回客户端($filename通过ajax确定)
print_r( array_values( $lines ));
我从 ajax 检索数据
success: function(docinfo){
alert(docinfo);
}
我得到这样的东西:
Array
(
[0] => 10
[1] => 123
[2] => 455
[3] => 325
[4] => 33
[5] => 3
)
但是当我想访问数组的值时
console.log(docinfo[0]);//which represents the first line of my txt file
我得到“A”,它是“Array”的第一个字母。不是我想要的 docinfo[0] 的值。
有没有一种方法可以发送数组并检索值,以便我可以按照我想要的方式使用它们?
【问题讨论】:
-
print_r 用于调试输出。它纯粹是一种基于字符串的格式,并不打算用于传递数据。你想要 json_encode()。
标签: javascript php arrays ajax