I assume you are using Ziggy or equivalent to user the route() helper in JS ?
Feb 14, 2023
18
Level 2
Ajax Post
Hi I am using two ajax request ajax in if block.
if (inputVal === "1") { e.preventDefault();
inputValue.value = 0;
$.ajax({
type: 'POST',
url: "{{ route('startScanner.post') }}",
});
buton.classList.remove('btn-primary');
buton.classList.add('btn-warning');
buton.textContent = 'Stop Scaning'
} else if (inputVal === "0") {
e.preventDefault();
inputValue.value = 1;
console.log('ajax a girecek mi')
$.ajax({
type: 'POST',
url: "{{ route('stopScanner.post') }}",
});
console.log('ajax a girdi')
buton.classList.remove('btn-warning');
buton.classList.add('btn-primary');
buton.textContent = 'Start Scan';
}
My problem is first url is. Error is : Route [startScanner.post] not defined. (View: /var/www/sub-domains/projectName/html/laravel-test/resources/views/page.blade.php)
Level 102
@onurzdgn Good. But they cannot be the same url
Route::post('page/start', [PageStationController::class, 'startScanner']) ->name('startScanner.post');
{{route('startScanner.post')}}
Route::post('page/stop', [PageStationController::class, 'stopScanner']) ->name('stopScanner.post');
{{route('stopScanner.post')}}
2 likes
Please or to participate in this conversation.