I’m trying to call the ajax once user had onclick
on the button, then the button will be passing the id to the controller to output the result in my modal’s div. However when I debug it show me the action you requested is not allowed.
Is there anything I can do about it on my code?
View :
<input type="" name="" value="VIEW" class="btn btn-primary m-t-15 waves-effect" data-toggle="modal" data-target="#defaultModal" onclick="refresh_detail('.$row["Task_ID"].')">
jQuery / AJAX Code:
<script type="text/javascript"> function refresh_detail(id){ $.ajax({ url : "<?= base_url()?>admin/Admintask/get_task_detail", type : "POST", dataType : "json", data : {"TaskID" : id}, success : function(data) { // do something }, error : function(data) { // do something } }); } </script>
Controller :
public function get_task_detail(){ echo $this->input->post('TaskID'); }
Advertisement
Answer
@Marcus as you are getting 403 due to CSRF Protection, you can add the URI to “csrf_exclude_uris” in the config.php file. Steps:
Open your “application/config/config.php“
Goto line 457 or where it written $config[‘csrf_exclude_uris’] = array();
Add your URI in the array, like
$config['csrf_exclude_uris'] = array('admin/Admintask/get_task_detail');
note: Confirm your URI from routes.php
This will exclude the URL from CSRF validation. You can learn more from here.