vendredi 23 juin 2017

Laravel AJAX 404 for route

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:

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

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

    $.ajax({
        url: '',
        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 (http://ift.tt/1RKky9Y).

Any input is much appreciated.

Cheers, Jules



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2tBCCNl
via IFTTT

Aucun commentaire:

Enregistrer un commentaire