将数据从数据表保存到MySQL数据库时出错 [英] Error saving data from Datatable to MySQL database

查看:91
本文介绍了将数据从数据表保存到MySQL数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//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, 
            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>');
            $('#action').attr('disabled', false);
            $('#item_data').DataTable().ajax.reload();                
        },
        error : function () {
            $('<div>').html('Found an error!');
        }
    })
});

那是我的Java代码,我试图调用php页面并将所有数据保存在我的数据库中.我收到一个错误:

That's my java code and I'm trying to call a php page and save all data in my DB. I got an error:

TypeError:未实现接口HTMLTableRowElement的对象上调用了'insertCell'.

TypeError: 'insertCell' called on an object that does not implement interface HTMLTableRowElement.

当我将数据插入表"it_det"中时会发生这种情况

That's happening when I insert data into the table "it_det"

看图片:

如果我不向表中插入新行,则不会出错! 怎么了为什么我会收到此错误??

If I don't insert new rows into the table I don't get error! What's wrong with that? Why I'm getting this error???

推荐答案

我发现将"processData"键更改为false的解决方案

I found the solution changing the "processData" key to false

$.ajax({
        processData: false, //The default value of ProcessData is true so changing in false I don't get any error.
        url:'item_action.php',
        method:"POST",

这篇关于将数据从数据表保存到MySQL数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆