403 Forbidden Access to CodeIgniter controller from ajax request

前端 未结 3 1479
离开以前
离开以前 2020-12-17 06:41

Im having trouble with sending an ajax request to codeigniter controller. It is throwing back a 404 Forbidden Access error. I have found some sort of similar question to thi

3条回答
  •  悲&欢浪女
    2020-12-17 07:16

    I was facing same problem but now I have fixed this problem.

    First of all, I have created csrf_token in header.php for every pages like below code

    $csrf = array(
                    'name' => $this->security->get_csrf_token_name(),
                    'hash' => $this->security->get_csrf_hash()
            );
    
    
    

    After that, when we are sending particular value through ajax then we will have to sent csrf token like below code

    $.ajax({
        url:"",
        data:{id:id,status:status,'security->get_csrf_token_name(); ?>': cct},
        method:"post",
        dataType:"json",
        success:function(response)
        {
            alert('success');
        }
    });
    

    I hope this code will help you because this is working for me.

提交回复
热议问题