简体   繁体   中英

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.

Using JSON stringify function I converted array into string and send, but on PHP side after decoding I am not getting the complete array.

Please let me know what I could be doing wrong

You can put json in a GET param by url encoding it.

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

And then in php read it like this

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

Be careful about the size of your list because URL's have a size limit of about 1~2kb. If you want to send a large amount of data you have to use POST.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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