gpt4 book ai didi

javascript - $.post - 从 javascript 到 php 的数组

转载 作者:行者123 更新时间:2023-11-28 20:15:48 25 4
gpt4 key购买 nike

我在 javascript 中有这个数组:

arr = [1, "string", 3]

这是我的 ajax 调用:

$.post("./ajax_book_client.php",
{'client_info[]': arr},
function(data) {
// some stuffs here
}
});

这是 php 摘录:

<?php 
$arr = $_POST['client_info'];

// I want to access the array, indexed, like this:
$arr[0] = 2;
$arr[1] = "Hello";
$arr[2] = 10000;

?>

但我收到此错误:

Uncaught TypeError: Illegal invocation jquery-1.8.3.min.js:2

正确的做法是什么?谢谢!

最佳答案

}); 中删除 } 以消除语法错误。

也不需要将 []client_info 一起使用,这样您就可以将其删除。

用途:

<script>
var arr = [1, "string", 3];
$.post("./ajax_book_client.php",
{'client_info': arr},
function(data) {
// some stuffs here
}
);
</script>

ajax_book_client.php

<?php 
$arr = $_POST['client_info'];

echo $arr[0];
echo $arr[1];
echo $arr[2];
?>

关于javascript - $.post - 从 javascript 到 php 的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19206004/

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