problems in add and update button are not working on a crud in data_table in php, my functions seem to be wrong

0
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
    $('#add_button').click(function(){
        $('#user_form')[0].reset();
        $('.modal-title').text("Add");
        $('#action').val("Add");
        $('#operation').val("Add");

});

var dataTable = $('#id_ato').DataTable({
    "processing":true,
    "serverSide":true,
    "order":[],
    "ajax":{
        url:"fetch.php",
        type:"POST"
    },
    "columnDefs":[
        {
            "targets":[6,7,8,9],
            "orderable":false,
        },
    ],

});

$(document).on('submit', '#user_form', function(event){
    event.preventDefault();
    var dt_public           = $('#dt_public').val();
    var tp_ato              = $('#tp_ato').val();
    var no_ato              = $('#no_ato').val();
    var Estado_uf_estado    = $('#Estado_uf_estado').val();
    var ementa              = $('#ementa').val();
    var link                = $('#link').val();
    var util                = $('#util').val();
    var especifico          = $('#especifico').val();



    if(dt_public != '' && tp_ato != '' && no_ato != '' && Estado_uf_estado != '' && ementa != '' && link != '' && util != '' && especifico != '')
    {
        $.ajax({
            url:"insert.php",
            method:'POST',
            data:new FormData(this),
            contentType:false,
            processData:false,
            success:function(data)
            {
                alert(data);
                $('#user_form')[0].reset();
                $('#userModal').modal('hide');
                dataTable.ajax.reload();
            }
        });
    }
    else
    {
        alert("Both Fields are Required");
    }
});

$(document).on('click', '.update', function(){
    var id_ato = $(this).attr("id_ato");
    $.ajax({
        url:"fetch_single.php",
        method:"POST",
        data:{id_ato:id_ato},
        dataType:"json",
        success:function(data)
        {
            $('#userModal').modal('show');
            $('#dt_public').val(data.dt_public);
            $('#tp_ato').val(data.tp_ato);
            $('#no_ato').val(data.no_ato);
            $('#Estado_uf_estado').val(data.Estado_uf_estado);
            $('#ementa').val(data.ementa);
            $('#link').val(data.link);
            $('#util').val(data.util);
            $('#especifico').val(data.especifico);
            $('.modal-title').text("Edit");
            $('#id_ato').val(data.id_ato);

            $('#action').val("Edit");
            $('#operation').val("Edit");
        }
    })
});
    
asked by anonymous 16.07.2018 / 16:22

0 answers