我只想将两个字段发送到.serialize()而不是整个表单。我想发送numberofwelds
和numberofconwelds
(前两名)。
我的表格:
<form action="" method="post" name="formsubmit" id="formsubmit" >
Number of welds: <input type="number" name="numberofwelds" id="numberofwelds" >
Number of construction welds: <input type="number" name="numberofconwelds"
id="numberofconwelds" >
Robot in/out: <input type="text" name="robotinout" disabled>
Weld time: <input type="text" name="weldtime" disabled>
Controlling cycle: <input type="text" name="concycle" disabled>
Total time (secs): <input type="text" name="totaltimesecs" disabled>
<input type="submit" value="Calculate" id="submit" name="submit">
</form>
如何发送整个表单。我只想发送两个字段而不是整个表单
var formData = $('#formsubmit').serialize();
$.get JSON ('calcsums.php', formData, sumresults);
如何只发送两个字段?
答案 0 :(得分:1)
您只能为要序列化的输入元素调用序列化。如果您只想序列化numberofwelds和numberofconwelds,那么
var formData = $('#numberofwelds, #numberofconwelds').serialize();
$.get('calcsums.php', formData, sumresults);
演示:Fiddle
答案 1 :(得分:1)
表单.serialize()方法将序列化所有表单字段,您可以更改代码,如下所示只发送两个字段
var formData = 'numberofwelds='+$('#numberofwelds').val()+'&numberofconwelds='+$('#numberofconwelds');
$.get('calcsums.php', formData, sumresults);