Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

onurzdgn's avatar

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)

0 likes
18 replies
vincent15000's avatar

I assume you are using Ziggy or equivalent to user the route() helper in JS ?

Sinnbeck's avatar

Show that route from your web.php

1 like
onurzdgn's avatar

@Sinnbeck Route::post('page', [PageStationController::class, 'startScanner'])->name('startScanner.get'); Route::post('page', [PageStationController::class, 'stopScanner'])->name('stopScanner.post');

Sinnbeck's avatar

@onurzdgn You have startScanner.get and stopScanner.post. Not startScanner.post ?

1 like
Sinnbeck's avatar

@onurzdgn What do you mean? How can the error be exactly the same? Maybe a similar error?

1 like
onurzdgn's avatar

@Sinnbeck Route [startScanner.start] not defined. (View: /var/www/sub-domains/projectName/html/laravel-test/resources/views/page.blade.php)

1 like
onurzdgn's avatar

@Sinnbeck I need two post. Just I change name startScanner.post to startScanner.get test. I need startScanner.post and stopScanner.post

1 like
Sinnbeck's avatar

@onurzdgn I didnt understand that. But the name of your routes need to match the name you call it with. Simple as that

Route::post('page', [PageStationController::class, 'startScanner'])
->name('startScanner.post'); //startScanner.post

//usage
{{route('startScanner.post')}}

Its as simple as that

3 likes
onurzdgn's avatar

@Sinnbeck Yes, I am using to but I am using two times

Route::post('page', [PageStationController::class, 'startScanner']) ->name('startScanner.post');

{{route('startScanner.post')}}

Route::post('page', [PageStationController::class, 'stopScanner']) ->name('stopScanner.post');

{{route('stopScanner.post')}}

1 like
Sinnbeck's avatar
Sinnbeck
Best Answer
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.