通过JavaScript数组 - > PHP [英] Pass Javascript Array -> PHP

查看:94
本文介绍了通过JavaScript数组 - > PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有一大堆的元素(50-200不等)的JavaScript数组。

Let's say I have a javascript array with a bunch of elements (anywhere from 50-200).

我想使用AJAX发送到PHP(prepared语句)。目前,我 .load 的PHP文件在一个循环内多次了,但我想将其转换成一个数组,并发送一次阵,加载PHP文件一次,而不是50-200倍。

I want to send that to PHP (prepared statement) using ajax. Currently, I .load a php file many times inside of a loop, but I want to convert that into an array and send the array once, loading the PHP file once instead of 50-200 times.

数组[我] =变量;

推荐答案

您可以使用 JSON.stringify(阵列)为en code在JavaScript中你的数组,然后用 $阵列= json_de code($ _ POST ['jsondata']); 在你的PHP脚本来检索它

You could use JSON.stringify(array) to encode your array in JavaScript, and then use $array=json_decode($_POST['jsondata']); in your PHP script to retrieve it.

这篇关于通过JavaScript数组 - > PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆