lundi 4 mars 2019

How to add a variable in ajax URL route

I am trying to concatenate a variable to my url link in ajax. The variable $news is the one that handles the notification id.

$(document).on("click", "#viewList", function() {

    $.ajaxSetup({
        headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    var $news = $(this).prop("value");
    $.ajax({
        type: "get",
        url : '', //returning an error undefined variable news
        data: {newsID : $news},
        success: function(store) {
            console.log(store);
            $('#rec').text(store);
        },
        error: function() {
          $('.alert').html('Error occured. Please try again.');
        }
    });

});

In my web.php, it's route is inside a route group.

Route::group(['middleware' => 'auth:admin'], function () {
    Route::prefix('admin')->group(function() {
        Route::get('/recipients/{news}', 'Admin\NewsController@recipients');
    });
});

So how can I make this work? By the way, my ajax is inside a blade.php file.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire