Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
       }
    });
});
Comment

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");
            }
        });
Comment

PREVIOUS NEXT
Code Example
Javascript :: adminlte 3 toasts 
Javascript :: javascript shuffle array 
Javascript :: how to pass an object directly to formdata in javascript 
Javascript :: a cypress command to refresh the whole page 
Javascript :: vue htmlWebpackPlugin.options.title 
Javascript :: js string to bytes 
Javascript :: javascript iterate through object properties 
Javascript :: discord.js leave guild 
Javascript :: find in array of objects javascript 
Javascript :: bootstrap modal popup disable click outside 
Javascript :: jquery trim 
Javascript :: how to set background automatically with my screen height 
Javascript :: access url query string from javascript 
Javascript :: sticky operations in javascript 
Javascript :: jquery check if iframe is loaded 
Javascript :: how use replace in js for all things at once 
Javascript :: div onchange react 
Javascript :: first x characters of string javascript 
Javascript :: node js check if a user exists in mysql 
Javascript :: react native status bar 
Javascript :: js to json 
Javascript :: how to add an image using jquery 
Javascript :: import axios 
Javascript :: moment + 1 day 
Javascript :: js union arrays 
Javascript :: nextjs socket.io 
Javascript :: react confirm alert 
Javascript :: location javascript redirect 
Javascript :: change word in string javascript 
Javascript :: how to check if a tag has any chidren 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =