Skip to content Skip to sidebar Skip to footer

Inserting Data In To Database Using Jquery/ajax,i Am Not Getting Ant Error But Values Not Inserting In To The Database

Inserting data in to database using jquery/ajax,i am not getting ant error but values not inserting in to the database using codeigniter,any mistake i done means please suggest me

Solution 1:

modified script

<script>
        $(document).ready(function(){
            $("#personal-info").submit(function(e){
               e.preventDefault();


               var suppid = $("#suppid").val();
               var proid = $("#proid").val();
               var custid = $("#custid").val();
                var message = $("#message").val();

                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>index.php/Profile_cntrl/buyer_communication",
                    data: {suppid:suppid,proid:proid,custid:custid,message:message},
                    success:function(data)
                    {
                        alert('SUCCESS!!');
                    },
                    error:function()
                    {
                        alert('fail');
                    }
                });
            });
        });
    </script>

controller public function buyer_communication() {

    $result1 = $this->Profile_model->fetch_Data($product_id);


    $Userid = $this->session->userdata('id');
    $result3 = $this->session->userdata('tt');
    $data4 = array(
        'message' => $this->input->post('message'),
        'supplier_id' => $this->input->post('suppid'),
        'product_id' => $this->input->post('proid'),
        'Customer_id' => $this->input->post('custid'),
        'From' => $result3,
    );

    $this->Profile_model->buyer_insert($data4);

    redirect('welcome/buyermessageview?id=' . $product_id);
}

Solution 2:

$("#personal-info").click(function () {
    e.preventDefault();

is not preventing the default postback because you didn't define e. Almost certainly your page is posting back rather than using ajax, because the script never has chance to run. Try:

$("#personal-info").click(function (e) {
    e.preventDefault();

Secondly, you aren't passing all the data to your server from the form. You only send "message", but it's clear the server requires other fields. You can send all your form fields automatically by putting this as the "data" field in your ajax call:

data: $(this).serialize()

You also said "I am not getting any error", but this is unlikely. If you checked your browser console (in the Developer Tools, by pressing F12 in most browsers) you would probably have seen the error "e is not defined" or similar, telling you that you had forgotten to define the variable.


Post a Comment for "Inserting Data In To Database Using Jquery/ajax,i Am Not Getting Ant Error But Values Not Inserting In To The Database"