Skip to content

Instantly share code, notes, and snippets.

@aayushdrolia
Created December 27, 2017 13:04
Show Gist options
  • Save aayushdrolia/99efaa3919aa00b5f6aa7dda3a5cd87a to your computer and use it in GitHub Desktop.
Save aayushdrolia/99efaa3919aa00b5f6aa7dda3a5cd87a to your computer and use it in GitHub Desktop.
Delete a post using Ajax with Laravel 5.5
$('body').on('click', '#delete', function () {
var post = $(this).parent().parent();
var postID = $(this).attr('item-id');
$.ajax({
dataType: 'json',
type: 'DELETE',
url: 'post/'+ postID,
headers : {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
data: {
id : postID,
"_token" : "{{csrf_token()}}"
}
})
.done(function (response) {
if (response) {
post.remove();
alert('Your post has been deleted successfully');
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment