I\'m having some issues with ajax and codeigniter. I\'ve already posted another question (link to question) and I thought I solved it, but I did not so I`m asking someone to wri
You must submit the CSRF token from cookies otherwise the request will be invalid, if you have CSRF enabled in config.php.
You can use this plugin to retrieve cookies in javascript. And simply pass it to CI.
ci_token
and
ci_cookie
keys may be different and can be found in config.php
I would also suggest setting up a route for the request and using
site_url()
over
base_url()
var SITE = "" // GLOBAL variable so your javascripts can be external
-
var data = { 'ci_token' : $.cookies.get('ci_cookie'), 'increase' : parseInt(number)}
$.ajax({
url : SITE + "/link/to/controller/method",
data : data,
});