Skip to content

Instantly share code, notes, and snippets.

@bbatsche
Created October 15, 2014 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bbatsche/d8760bbc517f85b2cd9c to your computer and use it in GitHub Desktop.
Save bbatsche/d8760bbc517f85b2cd9c to your computer and use it in GitHub Desktop.
Ajax Request
{{ link_to_action('PostsController@edit', 'Edit', $post->id, array('class' => 'btn btn-default')) }}
<button type="button" class="btn btn-danger delete-btn" data-post-id="{{{ $post->id }}}">Delete</button>
<script>
var csrfToken = "{{{ Session::get('_token') }}}";
$(".delete-btn").click(function() {
var postId = $(this).data('post-id');
if (confirm('Are you sure you want to delete this post?')) {
$.ajax({
url: '/posts/' + postId,
type: 'post',
data: {
_token: csrfToken,
_method: 'delete'
},
success: function(data) {
// Alert success
}
});
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment