“Laravel Ajax Excluir” Respostas de código

Ajax Exclua 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 Excluir

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

Respostas semelhantes a “Laravel Ajax Excluir”

Perguntas semelhantes a “Laravel Ajax Excluir”

Mais respostas relacionadas para “Laravel Ajax Excluir” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código