Created
May 23, 2023 09:29
-
-
Save johnadan/4e0b11cedefaae9b54f227e37c0bf76f to your computer and use it in GitHub Desktop.
ajax get request laravel blade
This file contains hidden or 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
<?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