gpt4 book ai didi

javascript - 如何读取从 php 脚本发送的数组的值

转载 作者:行者123 更新时间:2023-11-30 12:21:04 25 4
gpt4 key购买 nike

好的,我有一个 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] 的值。

有没有一种方法可以发送数组并检索值,以便按我想要的方式使用它们?

最佳答案

您是否尝试使用 json_encode() 打印数组? ?

echo json_encode(array_values($lines));

关于javascript - 如何读取从 php 脚本发送的数组的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31060147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com