我如何在javascript 的url 中传递一个数组?
我试过这个:
http://codeigniter/index.php/AssistanceMonitoringModule/assistanceMonitoring/getReport?remarks="+stat+"&sortBy="+sortBy+"&fromDate="+fromDate+"&toDate="+toDate+"&area="+区域;
remarks 是在 PHP 中作为数组捕获的那个,stat
是在 remarks
中提供的 javascript 数组。有什么解决办法吗?
每当在我使用 $this->input->get_post('remarks')
的 PHP 中捕获 remarks
时(因为我使用的是 codeigniter)我得到了一个错误“为 foreach() 提供的参数无效”
感谢您的帮助。 :)
最佳答案
您可以将数组编码为 JSON,使用 JSON.stringify
并使用 json_decode
在 PHP 中对其进行解码.不要忘记使用 encodeURIComponent
URL 中的值,否则您可能无法获得预期的 URL。
关于javascript - 在 url 中传递 javascript 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23728333/