[英]jquery post form with multiple same name field
I have a biling form with same input in (td) on each line (tr). 我在每行(tr)的(td)中都具有相同的输入形式的双语形式。 Now I want to submit this form with full filled lines only.
现在,我只想填写完整的表格。
I read some article on your site but I can't submit my form. 我在您的网站上阅读了一些文章,但无法提交表格。
Here is the html code: 这是html代码:
<div id="fac_table">
<table id="matable" width="100%">
<tbody>
<tr>
<th width="10px">
<img id="insArticle" src='../../images/icon_add.png' width='16' height='16'>
</th>
<th width="250px">
Désignation
</th>
<th width="30">
Unité
</th>
<th width="30">
Quantité
</th>
<th width="30">
Prix
</th>
<th width="30">
TVA
</th>
<th width="30">
Total
</th>
</tr>
<tr>
<td width="10px">
<img id="insArticle" src='../../images/icon_add.png' width='16' height='16'>
</td>
<td width="250px">
<input name="designation" type="text" class="facBig" />
</td>
<td width="30">
<input name="unite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="quantite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="prixUnite" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="taxe" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="totLine" type="text" class="facSmall" value="" />
</td>
</tr>
<tr>
<td width="10px">
<img id="insArticle" src='../../images/icon_add.png' width='16' height='16'>
</td>
<td width="250px">
<input name="designation" type="text" class="facBig" />
</td>
<td width="30">
<input name="unite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="quantite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="prixUnite" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="taxe" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="totLine" type="text" class="facSmall" value="" />
</td>
</tr> <tr>
<td width="10px">
<img id="insArticle" src='../../images/icon_add.png' width='16' height='16'>
</td>
<td width="250px">
<input name="designation" type="text" class="facBig" />
</td>
<td width="30">
<input name="unite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="quantite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="prixUnite" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="taxe" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="totLine" type="text" class="facSmall" value="" />
</td>
</tr> <tr>
<td width="10px">
<img id="insArticle" src='../../images/icon_add.png' width='16' height='16'>
</td>
<td width="250px">
<input name="designation" type="text" class="facBig" />
</td>
<td width="30">
<input name="unite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="quantite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="prixUnite" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="taxe" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="totLine" type="text" class="facSmall" value="" />
</td>
</tr> <tr>
<td width="10px">
<img id="insArticle" src='../../images/icon_add.png' width='16' height='16'>
</td>
<td width="250px">
<input name="designation" type="text" class="facBig" />
</td>
<td width="30">
<input name="unite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="quantite" type="text" class="facSmall" />
</td>
<td width="30">
<input name="prixUnite" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="taxe" type="text" class="facSmall" value="" />
</td>
<td width="30">
<input name="totLine" type="text" class="facSmall" value="" />
</td>
</tr>
</tbody>
</table>
</div>
and here is the jquery code: 这是jQuery代码:
$("#facform").submit(function()
{
var sendURL = $(this).attr("action");
var sendPost = $(this).attr("method");
var facArray = $(this).serialize();
alert(sendURL + " " + sendPost + " " + facArray);
$.ajax(
{
type: sendPost,
url: sendURL,
data: facArray,
success: function(response)
{
console.log(response);
}
});
});
$("#facform").submit();
The alert give the correct information, but I've a blank post on my sendfac.php. 该警报提供了正确的信息,但是我在sendfac.php上有一个空白的帖子。
Thank you for help. 谢谢你的帮助。
Add this code. 添加此代码。 You forgot to add your method.
您忘了添加方法。
$.ajax(
{
method: sendPost ,
url: sendURL,
data: facArray,
success: function(response)
{
console.log(response);
}
});
Or try with this code 或尝试使用此代码
$.post("/"+sendURL, { data: facArray}, function success (data) {
alert("Done");
}, "json");
You should add brackets to form fields names. 您应该在方格名称中添加方括号。 Because you are trying to send array of values.
因为您正在尝试发送值数组。
Like this: <input name="designation[]" type="text" class="facBig" />
像这样:
<input name="designation[]" type="text" class="facBig" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.