Ajax form submission not happening.

<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" />

My code is:

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

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

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


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

    var test = 'Test_post';


        url: '/addwishlist/test_ajax',
        type: 'POST',
        data: {post: test},
        dataType: 'JSON',
        cache: false,
        success: function(json){



In your controller add this

public function test_ajax()

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


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 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.