从ajax表单提交中获取null值



当我提交from时,我使用ajax从表单中获取null值。在当前情况下,我有3个字段,我没有从表单中获得任何值,请帮我找出解决办法。

<table class="table table-hover table-centered m-0 table-bordered">
<thead>
<tr>
<th>Sl</th>
<th style="width:10%;">name</th>
<th>email</th>
<th>Date</th>
</tr>
</thead>
<tbody id="purchaseData">
<tr>
<td>1</td>
<td><input type="text" class="form-control" id="quantity" name="name" placeholder="name" required=""></td>
<td><input type="text" class="form-control" id="costPrice" name="email" placeholder="500" required=""></td>
<td><input type="date" class="form-control" id="costPrice" name="email" placeholder="email" required=""></td>
<td>
<button type="button" class="btn btn-primary item-edit" id="btnSave">Submit</button>
</td>
</tr>
<tr>
<td>1</td>
<td><input type="text" class="form-control" id="quantity" name="name" placeholder="name" required=""></td>
<td><input type="text" class="form-control" id="costPrice" name="email" placeholder="500" required=""></td>
<td><input type="date" class="form-control" id="costPrice" name="date" required=""></td>
<td><button type="button" class="btn btn-primary item-edit" id="btnSave">Submit</button></td>
</tr>
</tbody>
</table>
$(function() {
$('#purchaseData').on('click', '.item-edit', function() {
var row = $(this).closest("tr")
var name = row.find("[name=name]").val();
var email = row.find("[name=email]").val();
var date = row.find("[name=date]").val();
$.ajax({
type: "POST",
url: "<?php echo site_url('Con_test/add_purchase_for_shop')?>",
dataType: "JSON",
data: {
'name': name,
'email': email,
'date': date
},
success: function(data) {
if (data == '1') {
var btn = $(this).closest("tr")
var name = inputData.find("button").prop('disabled', false).css(
"background-color", "green");
} else {
var btn = $(this).closest("tr")
var name = inputData.find("button").prop('disabled', true).css(
"background-color", "#2d7bf4");
}
}
});
});
});

您的日期名称是name="email",应该是name="date":

$(document).ready(function() {
$('#purchaseData').on('click', '.item-edit', function(event) {
event.preventDefault();
var row = $(this).closest("tr")
var name = row.find("[name=name]").val();
var email = row.find("[name=email]").val();
var date = row.find("[name=date]").val();
console.log('row ', row)
console.log('name ', name)
console.log('email ', email)
console.log('date ', date)
});
})

相关内容

  • 没有找到相关文章

最新更新