这是我第一次尝试使用ajax而不是Get . 我得到200响应,好像它正在工作,但控制器中的功能永远不会运行 .
我在我的ajax Get请求中使用了相同的概念,它们工作正常,但Post没有按预期工作,可排序('serialize')创建一个Post变量,所以我需要使用Post .
成功中的警报:函数总是像成功一样运行但是控制器函数永远不会被命中(我让它进行简单的数据库更改以验证它是否正在运行) .
阿贾克斯:
$(function() {
$('[id^="sortable_"]').sortable(
{
connectWith: '.sortable-line-item-list-5',
update : function (event, ui)
{
var items = $(this).sortable('serialize');
$.ajax({
type: 'post',
url: '/api/sort_order_item',
data: {
'items': items,
},
success: function()
{
alert('looks like it is working...');
},
});
}
});
$( '[id^="sortable_"]' ).disableSelection();
});
路线:
Route::post('api/sort_order_item', ['as' => 'api/sort_order_item', 'uses' =>'ApiController@SortOrderItem']);
控制器:
public function SortOrderItem()
{
$this_item = \pmms\Checklist_template_line_item::findOrFail(20);
$this_item->list_position = 1;
$this_item->save();
}
1 回答
我认为你的问题是csrf_token,把这一行放在你的刀片页头部分:
然后,像这样更新你的ajax代码:
如果它对您有帮助,请告诉我