'I am trying to delete record from database but unfortunately i am getting error using ajax

I am using sweet alert for deleting records but unfortunately i am getting error Cannot read properties of undefined (reading 'then') please help me how can i resolved that thank u.

please check error.

management:4547 Uncaught TypeError: Cannot read properties of undefined (reading 'then')

enter image description here

controller

public function destroy(Request $request)
    {
         $user = User::find($request->deleteId);
      // apply your conditional check here
      if (false) {
        $response['error'] = 'This user has something assigned to it.';
        return response()->json($response, 409);
      } else {
        $response = $user->forceDelete();
        return response()->json($response, 200);
      }
    }

ajax

$('.delete').click(function () {
      var deleteId = $(this).data('id');
      var $this = $(this);

      swal({
        title: 'Are you sure?',
        text: "You won't be able to revert this!",
        type: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#4fa7f3',
        cancelButtonColor: '#d57171',
        confirmButtonText: 'Yes, delete it!',
      }).then(function (result) {
        if (result.value) {
        axios
          .post('{{route("management.destroy")}}', {
            _method: 'delete',
            _token: '{{csrf_token()}}',
            deleteId: deleteId,
          })
          .then(function (response) {
            console.log(response);

            swal(
              'Deleted!',
              'Digitizing Order has been deleted.',
              'success'
            )
            table.draw();
          })
          .catch(function (error) {
            console.log(error);
            swal(
              'Failed!',
              error.response.data.error,
              'error'
            )
          });
        }
        })
    });


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source