mercredi 3 juillet 2019

Laravel controller not executing from ajax call

I have checkbox button, when it is clicked it sends an ajax request to the backend telling it the state of the box. However, the js is being executed, but i am seeing no signs of life in the controller method, even when putting Log::info etc.

The web route is:

Route::prefix("learn")->name("learn.")->middleware("auth.portal")->group(function (){
    ...
    Route::post("/lesson/viewed", "VideoController@setViewed")->name("setViewed");
});

The controller is:

public function setViewed(Request $request){
        ...
        DebugBar::info("setViewed Called...");
        ...
        return response()->json([
            "status" => "ok"
        ]);
    }

And the Ajax call is:

var vidId = JSON.parse(JSON.stringify( activeVidPlayButton.data("resources")))[0].lessonid;
        var status = me.is(":checked");
        const URL  = getBaseUrl() +  "learn/lesson/viewed";
        const postData = {
            lessonId: vidId,
            status: status,
            userId: userId
        };
        console.log(URL);

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $.ajax({
            url: URL,
            method: "POST",
            data: postData,
            error: function (jqXHR, textStatus, errorThrown) {
                console.log(errorThrown);
            },
            success: function (data, status, jqxhr) {
                console.log(data);
                console.log(status);
            }
        });

I'm expecting any signs of execution from the controller so I can work from there but am not seeing anything. The ajax request logs an empty console line for data, and status == "success", yet i do not see anything in the controller method working.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2XmSbv1
via IFTTT

Aucun commentaire:

Enregistrer un commentaire