Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As your event hook-up looks fine, i suspect that something is going wrong on the server side, which means that your success handler isn't firing. Try logging prior to your ajax call, to see if the click event fires at all:</p> <pre><code>$(".btn_mode").click(function(){ var mode_val = $(this).val(); var postdata={'mode':mode_val}; console.log('Posting mode_val: ' + mode_val); $.ajax({ type:"POST", url:"&lt;?php echo base_url();?&gt;superadmin/change_mode", dataType:'json', data:postdata, success: function(data){ if(data.notify=="Success") { console.log(data.notify); location.reload(); } else{ console.log(data.notify); } } }); }); </code></pre> <p>If the above logs the expected values when you click the buttons, that means that your php script is failing the first time you call it with <code>mode_val = 0</code>. </p> <p>You could try catching whatever exception might be thrown like so:</p> <pre><code>function change_mode(){ try{ $mode = $this-&gt;input-&gt;post('mode'); $query = $this-&gt;course_booking_model-&gt;change_mode($mode); if($query){ $notification = "Success"; } else{ $notification = "Failed"; } } catch(Exception $e){ $notification = $e-&gt;getMessage(); } echo json_encode(array('notify'=&gt;$notification)); } </code></pre> <p>Edit: The images you have uploaded indicate that there is a problem with the server-side code, and your button click is firing just fine. If you update your php to catch the error and return it, you should be able to get a hint as to what is going wrong. To see the call completing, you could implement the 'complete' and/or 'error' callbacks:</p> <pre><code> $.ajax({ type:"POST", url:"&lt;?php echo base_url();?&gt;superadmin/change_mode", dataType:'json', data:postdata, success: function(data){ if(data.notify=="Success") { console.log(data.notify); location.reload(); } else{ console.log(data.notify); } }, error: function(jqXhr, txtStatus, errThrown){ console.log('Call failed with status:' + txtStatus); if(errThrown) console.log('and error:' + errThrown); }, complete: function(jqXhr, txtStatus){ console.log('Call completed with status:' + txtStatus); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload