启用csrf_protection后,Ajax停止工作[重复]

This question already has an answer here:

I have changed the config file and set:

$config['csrf_protection'] = TRUE;

After this the ajax calls have stopped working, when I set to FALSE ajax starts working. I have to enable csrf_protection so how do I make my Ajax start working?

Error: Failed to load resource: the server responded with a status of 403 (Forbidden)

</div>

You need to set csrf token like this:

$(function($) {
    // this bit needs to be loaded on every page where an ajax POST may happen
    $.ajaxSetup({
        data: {
            csrf_test_name: $.cookie('csrf_cookie_name')
        }
    });

    // now you can use plain old POST requests like always
    $.post('site.com/controller/method', { name : 'Jerel' });
});

Source