douao3063 2016-12-30 12:30
浏览 42

您要求的操作不允许[重复]

This question already has an answer here:

i am try to get data using ajax in codeigniter but when i send request for get data to my controller at that time i get this error

The action you have requested is not allowed.

this is my ajax code

$.ajax({
     type:'POST',
    dataType: 'json',
    url: "redeem_drink/testjs",
    success: function(data){
        console.log(data);          
    },
    error: function(data){
        console.log(data);
    }
});

please help me how to setup ajax code for get and post data

</div>
  • 写回答

1条回答 默认 最新

  • du060334 2016-12-30 12:33
    关注

    The error is due to the CSRF value you have for the current submission. Which can be used to submit the form only once unless the value is updated by getting a new CSRF value as a response of the last form submit.

    Make sure you update the CSRF value or Reload the page which will automatically refresh the CSRF value.

    In your php code create a new CSRF value using the code.

    $csrf = array(
            'name' => $this->security->get_csrf_token_name(),
            'hash' => $this->security->get_csrf_hash()
    );
    
    return $this->output
                ->set_content_type('application/json')
                ->set_status_header(200)
                ->set_output(json_encode($csrf));
    

    and send the $csrf data as a response of last ajax submission of form.

    Now update the CSRF of the all the form using javascript.

    You can do that like this, Inside the success function.

    $('form').find('input[name='+data.name+']').val(data.hash);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示