weixin_33726318 2017-06-23 13:31 采纳率: 0%
浏览 45

Laravel AJAX 404用于路线

I am working on a Laravel 5.3 solution. I try to call a POST route via AJAX from one of my views to update a set of categories but I get a 404 error everytime I call the route.

Interesting fact: During development I was able to call the route with the JS-code shown below successfully - but since I did some updates to the controller code itself it throws a 404 but no exception.

Here is my controller action:

public function updateTree( Request $request )
{
    $data = $request->json()->all();

    $result = BlogCategory::rebuildTree($data, false);

    if($result > 0) {
        return Response::HTTP_OK;
    }
    return Response::HTTP_NOT_MODIFIED;
}

And here the JS AJAX call:

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

var updateTree = function (e) {
    var list = e.length ? e : $(e.target), output = list.data('output');

    console.log(JSON.stringify(list.nestable('serialize')));

    $.ajax({
        url: '{{ action('BlogCategoryController@updateTree') }}',
        type: "POST",
        data: JSON.stringify(list.nestable('serialize'))
    });
};

$(document).ready(function() {
    $('#nestable2').nestable({
        group: 1
    }).on('change', updateTree);
});

The controller route is bound like that in web.php

Route::post( '/service/blog/categories/updatetree', 'BlogCategoryController@updateTree' );

As you might see, I am using the Laravel NestedSet module from LazyChaser here (https://github.com/lazychaser/laravel-nestedset).

Any input is much appreciated.

Cheers, Jules

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Android URL如何转成视频/音频,可行吗?
      • ¥20 SQL数据查询,子查询
      • ¥15 c++字符串分割问题
      • ¥15 关于#sql#的问题:没有用命令关闭cdc,手动把系统表开启的cdc右键删除了
      • ¥15 vue+uniapp
      • ¥15 android freedom
      • ¥15 使用自定义的类型代替内置类型可行吗
      • ¥15 关于STM32的SPI和ENDAT接口编码器通信的问题
      • ¥15 关于#pdfbox#生成的PDF文件正常,转图片中文乱码的问题,如何解决?
      • ¥15 ADS中有关DAC控件的使用问题