I have a ul
list of items that can be sorted using JQueryUI sortable
. Currently, I am able to drag and rearrange the ul
items with no problem, and I am generating a console.debug message like I'd like, however, it doesnt seem to be posting the data to my controller's method which handles the data, and sends it to my model to update the SQL DB.
Basically, the admin will be shown a list of active pages on the site, and will allow them to rearrange the order of the navigation links on the front of the site.
$(document).ready(function() {
$('#sortable').sortable(
{
axis: 'y',
update: function (event, ui) {
var data = $('#sortable').sortable('serialize');
var getUrl = window.location;
var baseUrl = getUrl .protocol + "//" + getUrl.host + "/"
+ getUrl.pathname.split('/')[1];
console.debug(data);
// POST to server using $.post or $.ajax
$.ajax({
data: data,
type: 'POST',
url: baseUrl + '/admin/pages/update/'
});
}
}
);
});
Dragging an element in the list will generate a debug message,
id[]=2&id[]=1&id[]=3&id[]=4&id[]=7&id[]=6&id[]=5&id[]=8&id[]=9&id[]=10
which is set up perfect for what I'm attempting to do
The above SHOULD be posting to the following method of my Pages controller. I'm currently using a little hacked together code for my own learning, attempting to make it send a debug message. If I access /pages/update directly it will show the debug message, before redirecting me to /pages/index.
public function update()
{
echo '<script type="text/javascript">';
echo 'console.debug("Update Page Accessed:");';
echo '</script>';
redirect('admin/pages/index', 'refresh');
}
If I can get the debug message to show up after I drag an element, I'll be able to sort myself out from there.
Edit I just took a look at my JS console, and it seems that I've been hiding all my errors for Jquery.
POST http://localhost/~/admin/pages/update/ 500 (Internal Server Error)
Taking a look at my resources, it appears to be a CodeIgniter error being generated,
An Error Was Encountered. The action you have requested is not allowed.