jeudi 29 octobre 2015

laravel 5 route jquery sortable

I'm using Laravel 5 and use the jquery sortable: http://ift.tt/1eMUFGW

In my sortable.blade.php I have the following script:

  <script>
      $(function() {
          $('#sortMe').sortable({
              update: function(event, ui){
                  var postData = $(this).sortable('serialize');
                      console.log(postData);

                      $.ajax({
                          data: postData,
                               type: 'POST',
                               url: '{{ URL::to('sortable') }}'
                            });
                        }
                    });
                });
  </script>

Further the sortable.blade.php contains the following html

<div id="sortMe">
     <div id="item_1">Test1</div>
     <div id="item_2">Test2</div>
     <div id="item_3">Test3</div>
     <div id="item_4">Test4</div>
     <div id="item_5">Test5</div>
</div>

My route file contains the following:

Route::post('sortable', 'Sortable\SortableController@sortable');

In my SortableController I have at the moment an empty function:

public function sortable() {}

At the moment when I move one item within the div "sortMe", the firebug show me the moved items list : item[]=1&item[]=2&item[]=4&item[]=3&item[]=5 and give me an exception: POST http://localhost/myProject/sortable 500 Internal Server Error 261ms

Any ideas why I get this error? The purpose is that the after moving an item the sortable() function will be called which takes the moved items and save the order of the items within the database. At the moment it seems that there is a problem when calling the sortable() function. Thank you for any help!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire