Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

php - Codeigniter ajax post the action you requested is not allowed

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');
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@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:

  1. Open your "application/config/config.php"

  2. Goto line 457 or where it written $config['csrf_exclude_uris'] = array();

  3. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...