javascript - 将数据表记录保存到数据库时出错
问题描述
我正在尝试将数据保存在我的数据库中(请看下图)
但我收到此错误:
TypeError:在未实现接口 HTMLTableRowElement 的对象上调用了“insertCell”
//ADDING NEW ITEM INTO THE ITEM TABLE
$(document).on('submit', '#product_form', function(event){
event.preventDefault();
//btn_action="add_pricelvl"; //Set variable to call the add new item
var valdata = $(this).serialize(); //Array with field value
var tax = $('#item_tax').val(); //checkbox tax
var taxvalue = $('#item_taxvalue').val(); //inputbox tax
var tabledets = it_det //Read the detail table
.rows()
.data();
var arr1=[];
var i=0;
//Put the datatable rows in the array
for (i=0; i<tabledets.length; i++){
arr1[i]=tabledets.rows(i).data();
}
//call ajax function and send variable to php file.
$.ajax({
url:'item_action.php',
method:"POST",
data:{
//btn_action:btn_action, I can recovery this value in PHP file
valdata:valdata,
tax:tax,
taxvalue:taxvalue,
arr1:arr1
},
success : function(data)
{
$('#product_form')[0].reset();
$('#productModal').modal('hide');
$('#alert_action').fadeIn().html('<div class="alert alert-success">'+data+'</div>');
$('#alert_action').fadeIn().html(result);
$('#action').attr('disabled', false);
$('#item_data').DataTable().ajax.reload();
},
error : function () {
$('<div>').html('Found an error!');
}
})
});
<div class="row">
<div class="col-sm-12 table-responsive">
<table id="item_pricelvl" class="table table-bordered table-striped">
<thead>
<tr>
<th>Price Level</th>
<th>Pricing Method</th>
<th>From Quantity</th>
<th>To Quantity</th>
<th>Discount Amount</th>
<th>Unit Price</th>
<th><input type="checkbox" class="checkall" /></th>
</tr>
</thead>
</table>
</div>
</div>
如何复制数组中的数据表内容以将数据保存在 php 文件中????我必须以不同的方式做吗?
解决了
for (i=0; i<tabledets.length; i++){
arr1[i]=tabledets.row(i).data();
}
解决方案
推荐阅读
- android - 如何为 android deeplink/applink 管理两个不同的意图过滤器?
- javascript - 我可以通过 document.getElementsByClassName() 来处理 React 组件吗?
- html - `justify-content: space-around` 不起作用
- arrays - 通过指向其元素的指针修改数组的元素
- r - 如何将频谱图矩阵转换为 wav 文件
- json - 如何在json-schema Scala中为每个对象添加additionalProperties:false
- javascript - React.JS + axios 在 initialState 中解析错误。安装了axios
- python-3.x - 使用 django-rest-auth 和 allauth 进行 Google 身份验证
- javascript - Cloudinary 视频集成反应找不到元素 ID
- java - GRPC ConnectivityState 不能正常工作?