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 :: moment add seconds 
Javascript :: inarray javascript 
Javascript :: array from comma separated string javascript 
Javascript :: create number pyramid in javascript 
Javascript :: react native text input number only 
Javascript :: jquery $(...)..each() is not a function 
Javascript :: get last in array javascript 
Javascript :: angular string contains 
Javascript :: jest ReferenceError: TextEncoder is not defined 
Javascript :: a <route is only ever to be used as the child of <routes element" 
Javascript :: get element by tag name 
Javascript :: navigate-to-an-anchor-on-another-page 
Javascript :: how to map through array of iterators 
Javascript :: how to use sweet alert in vue js 
Javascript :: javascript object array iteration 
Javascript :: javascript create element in a new line 
Javascript :: regex empty string 
Javascript :: how to use custom stylesheets express node 
Javascript :: jquery word count 
Javascript :: document get element by id radio button 
Javascript :: jquery remove closest parent 
Javascript :: import { Application } from "express" 
Javascript :: get pods running on a node 
Javascript :: multiple transform properties javascript 
Javascript :: get all local storage 
Javascript :: javascript send post 
Javascript :: range javascript 
Javascript :: mongoose schema 
Javascript :: javascript string includes 
Javascript :: encode in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =