ajax csrf php,php - Codeigniter (CSRF) jQuery ajax problem - Stack Overflow

I’ve got a issue here, i keep getting a error when i try to post something with ajax (POST). I know it is the CSRF that gives me these problems and I’ve been tried back and forth trying to find a solution. However, i hope somebody here can help me out!

This is the error i keep getting (from google chrome inspector),

*Failed to load resource: the server responded with a status of 500 (Internal Server Error)

XHR finished loading: "http://localhost/woho/ajax/images".*

PHP (Controller)

class Ajax extends CI_Controller {

function images() {

echo 'Hello World';

}

}

Javascript

var ID = $(".imageWrap:last").attr("id");

var baseurl = "http://localhost/woho/";

var doScroll = 1;

var cct = $.cookie('csrf_cookie_name');

if (location.href == baseurl) {

$(window).scroll(function(){

if ($(window).scrollTop() > $('body').height() / 2) {

if(doScroll == 1) {

$.post(baseurl + 'ajax/images',{'id' : ID, 'csrf_token_name': cct}, function(data) {

alert(data);

$("#wrapper_content").append(data);

ID++;

});

}

}

});

}

my CCT var from javascript gives me the correct token or "hash" but when the javascript sends the ajax request codeigniter returns an error like,

An Error Was Encountered The action you have requested is

not allowed.

How can i fix this? do i need to validate the CSRF Token or something in my controller?

I'm using Codeigniter 2.0.3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值