[eluser]jshultz[/eluser]
I keep getting a 500 error when submitting an ajax request. If I turn off the CSRF in config then the posting works. Once I turn it on, though, then I get the 500 error again.
In config.php I have the following values set:
Code:
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
I do have jquery cookie being loaded and in my jquery file I have the following code:
Code:
$('#reorder').sortable({
opacity: '0.5',
update: function(e, ui){
newOrder = $( "#reorder" ).sortable('serialize');
csrf_cookie_name = $.cookie('csrf_cookie_name')
console.log(newOrder);
console.log(csrf_cookie_name);
$.ajax({
csrf_cookie_name: $.cookie('csrf_cookie_name'),
url: "/client/saveOrder",
type: "POST",
data: newOrder,
// complete: function(){},
success: function(feedback){
console.log('success');
$("#feedback").html(feedback);
//$.jGrowl(feedback, { theme: 'success' });
}
});
}
});
console.log of csrf_cookie_name right now is: cd660b153522bef89dc53f7f95cd6b1d so I am getting the value it seems?
And finally a really simple function in client that does the data handling. Normally I would separate some of this out into the model but I was trying to keep it simple until I got it working.
Code:
function saveOrder()
{
$items = $this->input->post('item');
echo '<br/>Items2:' . var_dump($items);
$total_items = count($this->input->post('item'));
for($item = 0; $item < $total_items; $item++ )
{
$data = array(
'pageid' => $items[$item],
'rank' => $item
);
$this->db->where('pageid', $data['pageid']);
$this->db->update('pages', $data);
// echo '<br />'.$this->db->last_query();
}
There's no form being used in the view. It's just an UL with a collection of LI's that I'm dragging around to sort.