传递 Javascript 数组 ->PHP [英] Pass Javascript Array -> PHP

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

问题描述

假设我有一个包含一堆元素(从 50 到 200 的任意位置)的 javascript 数组.

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

我想使用 ajax 将它发送到 PHP(准备好的语句).目前,我在循环内多次.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.

array[i] = variable;

推荐答案

你可以使用 JSON.stringify(array) 在 JavaScript 中编码你的数组,然后使用 $array=json_decode($_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天全站免登陆