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.
Laravel controller not executing from ajax call
Route::prefix("learn")->name("learn.")->middleware("auth.portal")->group(function () { ... Route::post("/lesson/viewed", "[email protected]")->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.
Gurpreet Singh Padam
In your
routes.php
file addThen use your ajax call to send data to
/orderdata
the data will be passed through to yourOrderData
method in theDashBoardController
So your ajax call would become
If you want to access the data you will need to add that into your method like so
And update your route to