0

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)

Andrea
  • 11,801
  • 17
  • 65
  • 72
Ameya
  • 69
  • 2
  • 10
  • The link on that page, beheist - where it is explained in details is rebuilding so have no access to it, I tried it before hence found no option but to post it myself, Thanks. – Ameya Aug 26 '15 at 08:56

1 Answers1

0

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

Muhammad Bilal
  • 2,106
  • 1
  • 15
  • 24