Skip to content

Instantly share code, notes, and snippets.

@ericlbarnes
Created July 22, 2015 02:18
Show Gist options
  • Save ericlbarnes/cec685ae9ea38afe57de to your computer and use it in GitHub Desktop.
Save ericlbarnes/cec685ae9ea38afe57de to your computer and use it in GitHub Desktop.
Example delete request
$(document).ready(function() {
$("button.remove").on('click', function(e){
e.preventDefault();
if ( ! confirm('Are you sure?')) {
return false;
}
var action = $(this).data("action");
var parent = $(this).parent();
$.ajax({
type: 'delete',
url: action,
data: '_token='+token,
beforeSend: function() {
parent.closest("tr").animate({'backgroundColor':'#fb6c6c'},300);
},
error: function(msg) {
alert(msg.responseJSON[0]);
},
success: function() {
parent.slideUp(300,function() {
parent.closest("tr").remove();
});
}
});
})
});
// Master layout:
<meta name="token" content="{{ csrf_token() }}">
// Button:
<button class="btn btn-circle btn-danger remove" data-action="/users/delete/{{ $user->id }}">
<i class="fa fa-trash-o"></i>
</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment