Last active
September 25, 2015 19:21
-
-
Save unicodeveloper/4288a5234bccdfc2413f to your computer and use it in GitHub Desktop.
Implementing Delete request to easily work with Laravel 5 - js file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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' | |
} | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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