我使用Laravel 5并使用jquery sortable: https://jqueryui.com/sortable/
在我的sortable.blade.php中,我有以下脚本:
<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>
此外,sortable.blade.php包含以下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>
我的路线文件包含以下内容:
Route::post('sortable', 'Sortable\SortableController@sortable');
在我的SortableController中,我现在有一个空函数:
public function sortable() {}
当我在div&#34; sortMe&#34;中移动一个项目时,萤火虫向我显示移动的项目列表:item [] = 1&amp; item [] = 2&amp; item [] = 4&amp;项[] = 3及项[] = 5 并给我一个例外: POST http://localhost/myProject/sortable 500内部服务器错误261ms
为什么我收到此错误的任何想法? 目的是在移动项目之后,将调用sortable()函数,该函数获取移动的项目并保存数据库中项目的顺序。目前,调用sortable()函数时似乎存在问题。谢谢你的帮助!