gpt4 book ai didi

jquery - 将一维数组发布到 db ajax post

转载 作者:太空宇宙 更新时间:2023-11-04 14:02:10 24 4
gpt4 key购买 nike

我有这个表单,它使用 jquery 加载函数加载详细信息这是表格

 <form id="form1" name="form1" method="post" action="">
<div id="tableBg">
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="list">
<thead>
<tr>
<th width="39%" scope="col">WHITE LIST</th>
<th width="61%" scope="col">&nbsp;</th>
</tr>
</thead>
</table>

<div style="max-height:400px; overflow-y:auto">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="list">
<tr class="sub_head">
<td scope="col"><strong>REG. NO.</strong></td>
<td scope="col"><strong>STUDENT NAME</strong></td>
<td scope="col"><strong>GRADE</strong></td>
<td scope="col"><strong>MESSAGE ID</strong></td>
</tr>
<tbody></tbody>
</table>
</div>
<div id="PageFooter">
<input type="submit" name="save_result" id="save_result" value="Save Results" />
</div>
</div>
</form>

然后从另一个页面加载下面的代码

do{
?>
<tr <?php echo (($x%2) != 0) ? '' : ' class="alternate-row row"' ?>>
<td scope="col"><?php echo $learners['reg_no'];?></td>
<td scope="col"><?php echo $learners['surname']." ".$learners['full_names']." (".$learners['nickname'].")";?></td>
<td scope="col"><?php echo $learners['grd']." ".$learners['grade_section'];?></td>
<td scope="col">
<input name="sms_id[<?php echo $learners['reg_no']; ?>]" type="text" size="3" />
</td>
</tr>
<?php $x++;}while($learners = $getLearners->fetch());

这段代码在一个表单中,底部有一个提交按钮。此 for 被发布到 process.php 中,其中包含以下代码,打印一些输出

if(isset($_POST['submit'])){

foreach($_POST['sms_id'] as $reg=>$msg_id){
echo $reg. " / ".$msg_id;
}

}

如果表单直接从表单发布到 process.php,上面会显示两个值

但我想使用 ajax 并尝试了以下不起作用的代码。仅发布 $msg_id 而不是其他值。

var formData = $("#form1").serializeArray();
$.ajax({
url: "models/process.php",
type: "POST",
data: formData,
success: function(data)
{
alert(data);
}
});

此代码无效,有人可以帮忙吗?提前致谢。

JDK

最佳答案

我不知道这是否会有很大帮助,但尝试添加传统的 ajax 选项

    $.ajax({
url: "models/process.php",
type: "POST",
traditional: true,
data: formData,
success: function(data)
{
alert(data);
}
});

这改变了 Ajax 序列化其数据的方式。

关于jquery - 将一维数组发布到 db ajax post,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26423394/

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