mercredi 1 mars 2017

Refer to Laravel route that have a prefix - Javascript AJAX - Laravel 5.3

I have a problem with my route files and refering to th routes with Ajax. Here is a snipit of all relevant routes and the ajax Code :

in the web.php ( base route file ) i'm including the routes I need

require_once base_path('routes/shoppingcard.routes.php');

Now in my shoppingcard.routes.php is this route group that bugs me

Route::group(['prefix' => 'shoppingCard'], function () {
    // add Produkt
    Route::post('addToBasket', ['as' => 'addToBasket', 'uses' => 'Shop\Frontend\AjaxController@index']);
});

I want to refer to the addToBasket route but wasn't really successful until now

Thats my Ajax code:

$(document).on('click', '#addToBasket', function () {
    var quantitie = $('input[type=number]').val();
    $.ajax({
        type: "post",
        url: "/shoppingCard/addToBasket",  // <----- Route I try to refer to
        data: {'id': $(this).data("id"), 'quantitie': quantitie},
        dataType: 'JSON',
        success: function (data) {
           // not important
        },
        error: function (data) {
           // not important
        }
    });
});

Now I tried many things out to refer to the route correctly but I always get a 500 or a 404

I'm using Laravel 5.3

The error I currently get in my console:

http://ift.tt/2lWsjQu [HTTP/1.0 500 Internal Server Error 49ms]

But the path (shoppingCard/addToBasket) looks totaly fine so why I get a error? I'm a little bit confused about that

Thanks for any help!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire