“Laravel Ajax Delete” Ответ

Ajax Delete Laravel

//route
Route::delete('/dashboard/booking/deletebooking/{id}','ResourceController@deletebooking')->name('works.deletebooking');

//resource controller
public function deletebooking($id){
    $booking = Booking::where('id','=',$id)->get();
    $booking->delete();

    return response()->json(['success' => true],200);
}

//javascript 
$.ajax(
        {
            url: "/dashboard/booking/deletebooking/"+id,
            dataType: "JSON",
            type: 'DELETE',
            data: {
                '_token': $('meta[name=csrf-token]').attr("content"),
            },
            success: function ()
            {
                console.log("it Work");
            }
        });
Ahmed

Laravel Ajax Delete

This is a User delete example :

$(".userBtn").click(function(){
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $.ajax(
    {
        url: "user/delete/"+id,
        type: 'delete', // replaced from put
        dataType: "JSON",
        data: {
            "id": id // method and token not needed in data
        },
        success: function (response)
        {
            console.log(response); // see the reponse sent
        },
        error: function(xhr) {
         console.log(xhr.responseText); // this line will save you tons of hours while debugging
        // do something here because of error
       }
    });
});
Wandering Wolverine

Ответы похожие на “Laravel Ajax Delete”

Вопросы похожие на “Laravel Ajax Delete”

Больше похожих ответов на “Laravel Ajax Delete” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования