Codeigniter ajax post csrf不允许您请求的操作

时间:2015-12-04 16:14:03

标签: php jquery ajax codeigniter

我有ajax请求获取信息,如果用户仍然登录或不让我们说检查其会话,并且我也启用了csrf protectionGET是在所有方面工作正常,但问题仅在于POST from ajax,我也关闭了re-generation of token并且还将新令牌传递给每个ajax请求,但它仍然给我一个错误:

The action you have requested is not allowed.

获取令牌:

var getToekn = function(){
 return $('meta[name=csrf_token]').attr('content');
}

每1分钟调用一次userLog:

var userLog = function () {
    var formdata = new FormData();
    formdata.append('csrf_',getToken);
    $.ajax({
        url: site_url + 'action=userCheck',
        type: 'post',
        dataType: 'json',
        data:formdata,
        processData:false,
        success: function (d) {
            if (d.login === 'true') {
                jQuery('meta[name="csrf_token"]').attr('content', d.csrf);
                console.log('loggedin: True');
            } else if (d.login === 'false') {
                if (jQuery('#js_login_again').legnth) {
                    popup('js_login_again', 'o');
                    jQuery('meta[name="csrf_token"]').attr('content', d.csrf);
                } else {
                    $.ajax({
                        url: site_url + '?pop=loginagain',
                        type: 'post',
                        dataType: 'html',
                        success: function (data) {
                            var popup = $(data).filter('#js_login_again');
                            jQuery('body').append(popup);
                            popup('js_login_again', 'o');
                            loading('h');

                        }
                    });
                }
            }
        }
    });
}

我确实检查了发送的令牌是否正确并且它是一个正确的令牌,但是ajax post请求仍然导致错误The action you have requested is not allowed.

事情是我已经将csrf令牌提供给ajax请求,并且令牌也被添加到发送到url的参数中,所以不是令牌的情况,我不知道。我只是失去了为什么会这样做。

还检查了$ this-> input->帖子(' csrf _');它是空的。

0 个答案:

没有答案