Skip to content

Instantly share code, notes, and snippets.

@unicodeveloper
Last active September 25, 2015 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unicodeveloper/4288a5234bccdfc2413f to your computer and use it in GitHub Desktop.
Save unicodeveloper/4288a5234bccdfc2413f to your computer and use it in GitHub Desktop.
Implementing Delete request to easily work with Laravel 5 - js file
$(document).ready(function() {
$("button.delete").on('click', function(e){
e.preventDefault();
if ( ! confirm('Are you sure?')) {
return false;
}
var action = $(this).data("action");
var parent = $(this).parent();
var token = $(this).data("token");
$.ajax({
type: 'POST',
url: action,
data: { _token: token, _method: 'delete' },
error: function(msg) {
alert(msg.responseJSON[0]);
},
success: function() {
window.location.href = '/projects'
}
});
});
});
<button class="btn btn-circle btn-danger delete"
data-action="{{ url('projects/' . $project->id) }}"
data-token="{{csrf_token()}}">
<i class="fa fa-trash-o"></i>Delete
</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment