Skip to content

Instantly share code, notes, and snippets.

@johnadan
Created May 23, 2023 09:29
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 johnadan/4e0b11cedefaae9b54f227e37c0bf76f to your computer and use it in GitHub Desktop.
Save johnadan/4e0b11cedefaae9b54f227e37c0bf76f to your computer and use it in GitHub Desktop.
ajax get request laravel blade
<?php
@foreach(jobs as $job)
<button class="btn btn-danger rmvbtn-jo" data-id="{{ $job->id }}" style="border: none; background-color:transparent;">
<i class="fas fa-trash fa-lg text-danger"></i>
</button>
@endforeach
$(document).on('click', '.rmvbtn-jo', function () {
var jo_id = $(this).data('id');
console.log('job order id: ' + jo_id);
if(confirm("Are you sure you want to remove this job order?")){
$.ajax({
type: "POST",
url: env + "/job-orders/" + jo_id,
success: function (response) {
console.log('Success:', response)
alert('Successfully removed job order');
location.reload();
},
error: function (error) {
console.log('Error:', error.statusText);
alert('Failed to remove job order');
}
});
}
});
Route::post('/{id}', [JobOrderController::class, 'destroy'])->name('destroy');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment