Ajax form submission not happening.
view:

<form method="post" name="addwishlists" id="addwishlists" enctype="multipart/form-data" >
 <input type="hidden" name="deal_id" value="<?php echo $deal_id; ?>" >
<input type="hidden" name="cust_id" value="<?php echo $cust_id; ?>">

                                    <input type="submit" value="Add Wishlist" id="addwishlist" class="btn btn-primary" />
                                    </form>

My code is:

<script>   //no need to specify the language
$(document).ready(function(){
  $("#addwishlist").click(function(e){  // passing down the event 

    $.ajax({
       url:'<?php echo base_url();?>add-wishlist',
       type: 'POST',
       data: $("#addwishlists").serialize(),
       success: function(){
           alert("wishlist added");
           $('#deal_id').val('');
           $('#cust_id').val('');
       },
       error: function(){
           alert("Fail")
       }
   });
   e.preventDefault(); // could also use: return false;
   //return false;
 });
});
</script>

Do you get any errors in you console.log? I usually add my e.preventDefault() at the top of my function, before the ajax.

try:

$('#addwishlist').on('click', function(e){
    e.preventDefault();

    var test = 'Test_post';

    $.ajax({

        url: '/addwishlist/test_ajax',
        type: 'POST',
        data: {post: test},
        dataType: 'JSON',
        cache: false,
        success: function(json){
            alert(json.message);
            console.log(json.post);
        }

    });

});

In your controller add this

public function test_ajax()
{

    $data = array('message' => 'Ajax Form Success', 'post' => $this->input->post(NULL, TRUE));


    $this->output->set_content_type('application/json')->set_output(json_encode($data));
}

You are sending your form data to a test function in you controller and then outputing a JSON string, and catching it in your success callback function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.