简体   繁体   English

如何在查询字符串中将多维数组从JavaScript发送到PHP

[英]How to send multidimensional array from JavaScript to PHP in query string

I am using following code: 我正在使用以下代码:

window.location.assign("index.php?module=pengu_dispatch&action=cover_letter&value="+list);

Here I want to send multidimensional array in query string to the PHP file. 在这里,我想查询字符串中发送多维数组到PHP文件。

Using JSON stringify function I converted array into string and send, but on PHP side after decoding I am not getting the complete array. 使用JSON stringify函数,我将数组转换为字符串并发送,但是在解码后的PHP端,我没有得到完整的数组。

Please let me know what I could be doing wrong 请让我知道我可能做错了

You can put json in a GET param by url encoding it. 您可以通过url编码将json放在GET参数中。

url = 'http://whatever/some.php?param='+encodeURIComponent(JSON.stringify(list))

And then in php read it like this 然后在php中像这样阅读

$list = json_decode($_GET['param']);

Be careful about the size of your list because URL's have a size limit of about 1~2kb. 请注意列表的大小,因为URL的大小限制约为1〜2kb。 If you want to send a large amount of data you have to use POST. 如果要发送大量数据,则必须使用POST。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM