I am posting data to controller like this:
var postVars = new Array();
postVars[0] = key;
postVars[1] = haveCredits;
postVars[2] = creditsNeeded;
postVars[3] = creditsLeft;
//alert(postVars.join("&"));
xhr.open('POST', 'ajax');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(postVars.join("&"));
How can i retrieve this values in my controller function?
Controller code:
$variableValues= explode('&',$this->input->post('postVars'));
It is returning an empty array.
Thanks in advance.
Change last row like this:
Now
$variableValues= explode('&',$this->input->post('postVars'));should work.Btw, i would like to introduce you to jQuery. It’s one of the most popular JavaScript libraries and has very powerfull AJAX API.