首页 > 解决方案 > 将数据表记录保存到数据库时出错

问题描述

我正在尝试将数据保存在我的数据库中(请看下图)

在此处输入图像描述

但我收到此错误:

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();	
}

标签: javascriptphpjqueryhtml

解决方案


推荐阅读