gpt4 book ai didi

javascript - 通过 AJAX 从大格式发送数据

转载 作者:行者123 更新时间:2023-11-28 16:02:02 27 4
gpt4 key购买 nike

我有一个包含 30 个字段的表单:3 个字段重复 10 次。这是我的代码:

<form id="artikelform" method="POST" name="controleartikelen" action="">
<table id="controle">
<tr><th>Maakartikel</th><th>Aantal</th><th>Leverdatum</th></tr>
{for $i=1 to 10}
<tr>
<td><input type="text" name="artikel" class="artinput"/></td>
<td><input type="text" name="aantal" class="aantalinput"/>&nbsp;x</td>
<td><input type="text" name="datum" class="dateinput"/></td>
</tr>
{/for}
</table>
<input type="button" onclick="javascript:startControle();" value="Controleer"/>
</form>

我想通过 AJAX(POST 方法)将表单值发送到 PHP 脚本。我尝试使用我的ajax作为POST数据发送 $.param($("#artikelform").serializeArray()); 但该函数的结果不可用(只是很多变量以某种 GET 格式)。将此表单与 AJAX 结合使用的最佳方式是什么?也许使用 serializeArray() 的另一种方式?

编辑:

这是我的 AJAX 请求代码:

$.ajax({
url: 'myscript.php',
cache: false,
data: formdata,
type: "POST"
}).done(function(data){
$("#resultwrapper").html(data);
})

最佳答案

或者:

1) 使用 PHP 函数 json_decode() 将 JSON 编码的数据结构映射到 PHP 数组,或者

2) 不要序列化有效负载,而是将变量命名为 php 数组:

    <tr>
<td><input type="text" name="artikel[]" class="artinput"/></td>
<td><input type="text" name="aantal[]" class="aantalinput"/>&nbsp;x</td>
<td><input type="text" name="datum[]" class="dateinput"/></td>
</tr>

关于javascript - 通过 AJAX 从大格式发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16671883/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com