gpt4 book ai didi

ajax - jquery ajax多表单提交

转载 作者:行者123 更新时间:2023-12-01 03:19:23 26 4
gpt4 key购买 nike

需要一点帮助。今天我的 jQuery 运行得很顺利,直到我碰壁了。我试图通过 AJAX 动态编辑多个表单(单个行项目),并带有文本提交链接或某种提交按钮。问题是,我可以让它通过 AJAX 提交表单,但没有表单中的任何数据...即点击提交,它发送请求,但没有查询字符串。有人可以帮我确定缺少什么吗?

这是我的 jquery:

        $('.submitLineChanges').click(function() {
var formID = $(this).closest('form').attr('ID')
datastring = $(formID).serialize();
$.ajax({
type:'POST',
url: 'update_ajax.asp',
data: datastring,
success: function(response) {
alert("Success " + id)
//$('#ContactForm').find('.form_result').html(response);
}//end ajax options
});//end ajax
return false;
});//end of click function

还有我的表格:

    <form id="line-item-<%= intRecID %>-form" class="submitLineForm">
<input type="hidden" name="UpdateLineItem" value="true" />
<span class="edit" id="edit-line-<%= intRecID %>" style="display: none;">
<span class="quantity"><input name="part_qty" id="part_qty_<%= intRecID %>" type="text" value="<%=FormatNumber(rs("quote_part_qty"),0)%>"></span>
<span class="partno"><input name="part_no" id="part_no_<%= intRecID %>" type="text" value="<%=rs("quote_part_id")%>"></span>
<span class="descrip"><Textarea name="part_descrip" type="text" id="descrip<%= intRecID %>" rows="3"><%=rs("quote_part_descrip")%></Textarea></span>
<span class="sellprice">$<input name="part_sale" id="part_sale_<%= intRecID %>" type="text" value="<%=FormatNumber(rs("quote_part_sale"),2)%>"></span>
<span class="margin" id="emargin_<%= intRecID %>"><%=margin%></span>
<span class="cost"><strong>Cost: </strong>$<input name="part_cost" id="part_cost_<%= intRecID %>" type="text" value="<%=FormatNumber(cost,2)%>"></span>
<span class="wt"><strong>Weight: </strong><input name="part_wt" id="part_wt_<%= intRecID %>" type="text" value="<%=FormatNumber(rs("quote_part_wt"),2)%>"></span>
<span class="update"><input type="button" value="Save Changes" class="submitLineChanges" /></span>
</span>
</form>

正如您应该能够看出的,我在 ASP 中运行它。该表格基本上适用于购物车中的每个订单项。由于页面的性质,我不想有一个单独的页面来编辑所有信息。看来这应该可行,但我现在所处的狭隘视野中很可能错过了一些东西。

我应该注意,表单是针对每一行的,我不需要它来提交所有表单,只需提交一个表单。

谢谢

最佳答案

改变

datastring = $(formID).serialize();

var datastring = $('#' + formID).serialize();

您需要使用 ID 选择器使用 # 前缀。另外 - 如果没有 var 关键字,您就会无缘无故地污染全局命名空间。

或者甚至更好......你可以替换

var formID = $(this).closest('form').attr('ID');
var datastring = $('#' + formID).serialize();

var datastring = $(this).closest('form').serialize(); 

它找到表单并一次性将其全部序列化!!

感谢@MikeBrant对于这个建议。

关于ajax - jquery ajax多表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11670690/

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