Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在jquery中获取输入数组的值并将其传递给PHP_Jquery_Html_Ajax - Fatal编程技术网

在jquery中获取输入数组的值并将其传递给PHP

在jquery中获取输入数组的值并将其传递给PHP,jquery,html,ajax,Jquery,Html,Ajax,我有多个输入字段,如下所示: <input type="text" name="childage[3]" placeholder="0"/> <input type="text" name="childage[8]" placeholder="0"/> <input type="text" name="childage[12]" placeholder="0"/> <input class="age-box" type="text" name="chi

我有多个输入字段,如下所示:

<input type="text" name="childage[3]" placeholder="0"/>
<input type="text" name="childage[8]" placeholder="0"/>
<input type="text" name="childage[12]" placeholder="0"/>
<input class="age-box" type="text" name="childage[3]" placeholder="0"/>
<input class="age-box" type="text" name="childage[8]" placeholder="0"/>
<input class="age-box" type="text" name="childage[12]" placeholder="0"/>

var ages = $('.age-box').serialize();
$.post(url, ages, function(data) { //handle response from the server });

您应该看看
序列化方法:

您需要获取所有表单元素,如下所示:

<input type="text" name="childage[3]" placeholder="0"/>
<input type="text" name="childage[8]" placeholder="0"/>
<input type="text" name="childage[12]" placeholder="0"/>
<input class="age-box" type="text" name="childage[3]" placeholder="0"/>
<input class="age-box" type="text" name="childage[8]" placeholder="0"/>
<input class="age-box" type="text" name="childage[12]" placeholder="0"/>

var ages = $('.age-box').serialize();
$.post(url, ages, function(data) { //handle response from the server });

var ages=$('.age-box').serialize();
$.post(url、年龄、函数(数据){//处理来自服务器的响应});

您应该看看
序列化方法:

您需要获取所有表单元素,如下所示:

<input type="text" name="childage[3]" placeholder="0"/>
<input type="text" name="childage[8]" placeholder="0"/>
<input type="text" name="childage[12]" placeholder="0"/>
<input class="age-box" type="text" name="childage[3]" placeholder="0"/>
<input class="age-box" type="text" name="childage[8]" placeholder="0"/>
<input class="age-box" type="text" name="childage[12]" placeholder="0"/>

var ages = $('.age-box').serialize();
$.post(url, ages, function(data) { //handle response from the server });

var ages=$('.age-box').serialize();
$.post(url、年龄、函数(数据){//处理来自服务器的响应});

您可以使用隐藏的输入字段,并将值设置为所需的数字:

<input type="hidden" value=3 />
<input type="hidden" value=8 />
<input type="hidden" value=12 />

// Get the values
$('input[type="hidden"]')[0].val();
$('input[type="hidden"]')[1].val();
$('input[type="hidden"]')[2].val();

//获取值
$('input[type=“hidden”]”)[0].val();
$('input[type=“hidden”]”)[1].val();
$('input[type=“hidden”]')[2].val();

您可以使用隐藏的输入字段,并将值设置为所需的数字:

<input type="hidden" value=3 />
<input type="hidden" value=8 />
<input type="hidden" value=12 />

// Get the values
$('input[type="hidden"]')[0].val();
$('input[type="hidden"]')[1].val();
$('input[type="hidden"]')[2].val();

//获取值
$('input[type=“hidden”]”)[0].val();
$('input[type=“hidden”]”)[1].val();
$('input[type=“hidden”]')[2].val();

注意,serialize将取代url编码的
[
]
。您必须将它们替换回
$(“.age box”).serialize().replace(/%5B/g,[').replace(/%5D/g,['))或类似的。谢谢!在php中,我使用了parse_str($_POST['fields'],$fields);请注意,serialize将取代url编码的
[
]
。您必须将它们替换回
$(“.age box”).serialize().replace(/%5B/g,[').replace(/%5D/g,['))或类似的。谢谢!在php中,我使用了parse_str($_POST['fields'],$fields);它是有效的