Skip to content

Instantly share code, notes, and snippets.

@ericlbarnes

ericlbarnes/app.js

Created Jul 22, 2015
Embed
What would you like to do?
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