Php 序列化数组并将其发布到进程文件
我正在尝试将数组发布到另一个要处理的文件。数组位于下面,它正确填充行。我在脚本标记的开头初始化了它,使其成为全局的。Php 序列化数组并将其发布到进程文件,php,javascript,Php,Javascript,我正在尝试将数组发布到另一个要处理的文件。数组位于下面,它正确填充行。我在脚本标记的开头初始化了它,使其成为全局的。 在javascript中: var locationsall = new Array(); locationsall[counter] = new Array(); locationsall[counter][0] = address; locationsall[counter][1] = lat; locationsall[counter][2] = lng; 在我的表格里,
在javascript中:
var locationsall = new Array();
locationsall[counter] = new Array();
locationsall[counter][0] = address;
locationsall[counter][1] = lat;
locationsall[counter][2] = lng;
在我的表格里,我试着把它连载并发布
<input type="hidden" name="result" value="<?php echo serialize($locationsall); ?>">
我做错了什么?当您通过jQuery更新客户端数据时,需要将result的值设置为您想要传递的值。您可以使用序列化JS对象,这样就可以将JSON编码的数据传递给PHP。处理post数据时,您需要在
$\u post['result']
JS
PHP
输入元素的value属性中显示了什么?当我检查页面源时,显示为value=“N;”。。。不确定这意味着什么该值为空。可以显示表单的更多内容吗?应该更改document.form.result的值是什么?单击第二个单选按钮并添加地址将启动codeAddress()方法,该方法填充locationsall数组
$locations = unserialize($_POST['result']);
var test = new Array('a', 'b');
var data = $.param(test);
$('#result').val(data);
...
if (isset($_POST['result'])) {
$data = (array) json_decode($_POST['result']);
}