Getting 500 error with CI 2.0.x, ajax and CSRF enabled |
[eluser]Matalina[/eluser]
100% certain it works: Here is the ajax documentation on data Quote:data Object, String
[eluser]CroNiX[/eluser]
POST data is not sent as JSON. You have the choice to use a json object for the post values, or enter a manually generated query string (which is what serialize() does). A post string looks pretty much like a query string (separated by ampersands), just sent via a different method. jQuery takes your json object internally and translates it to a POST string when sending it out. Check out the headers sent along with a form from any website using POST, even the one using jquery. It will look like that.
[eluser]beaufrusetta[/eluser]
[quote author="Matalina" date="1339522097"]100% certain it works: Here is the ajax documentation on data Quote:data Object, String[/quote] Badass! Then that helps out my jQuery quite a bit...
[eluser]CroNiX[/eluser]
You can also just use the jQ shortcut, $.post(), instead of $.ajax specifying the POST "type". It's shorter codewise. Code: $.post(
[eluser]jshultz[/eluser]
This isn't going to be a form, though. It's an UL with a list of LIs. I'm using the jquery plugin to allow me to be able to reorder the li's. When the li position is updated then it updates the db with the new ranking order for the pages. So, in short, there isn't any form data.
[eluser]CroNiX[/eluser]
jQueryUI sortable has it's own serialize method just for that http://jqueryui.com/demos/sortable/#method-serialize In your sortable "change" event (or however you are choosing to save the sorted order), just do an ajax $.post() sending the sortable order as data using the serialize() method. Basically the same thing as above except sending the sortable serialized object instead of a serialized form. Just append the csrf data to it when sending.
[eluser]CroNiX[/eluser]
It would be something like Code: newOrder = $( "#reorder" ).sortable('serialize'); Strange, the forum is adding a semicolon after &csrf; there...
[eluser]jshultz[/eluser]
Got it! Thanks guys! My code ended up looking like this: I used both the token name and the name of the cookie to get it to work. I couldn't have done it without your help. Thanks! Code: $('#reorder').sortable({ |
Welcome Guest, Not a member yet? Register Sign In |