How to make ajax delete request with laravel 5

Published Date: 25-Nov-2017 | Tags: Laravel 5.5  JQuery  Ajax  

This tutorial I want to show you how to use jquery ajax to create delete request with laravel 5. And suppose that you already know how to use delete request in laravel route. 

function ajaxDelete(url, token, content) {
    // content is an id of div. And it is used for showing the updated data after deleting.
    // if you not specify, it will use div with id "content"
    content = typeof content !== 'undefined' ? content : 'content';
    $('.loading').show();   // in case you have loading animation
        type: 'POST',
        data: {_method: 'DELETE', _token: token},       // token is a laravel token {{csrf_token}}
        url: url,      // url is the url you define in laravel delete route
        success: function (data) {
            $("#" + content).html(data);
        error: function (xhr, status, error) {

Hope you understand what I want to show you.

© 2018 All Rights Reserved.