Support the ongoing development of →
Session Authentication JavaScript
Last updated 2 years ago.

tomassbo, davidningthoujam liked this thread


Hello Tomas,

How are you routes defined? Do they share the same middleware? (Do they have the same session handler). Else you have a new session for the AJAX request then for your normal page.

And you should return the data and not echo it. (Laravel will transform an array to json or you can create a new JsonResponse. So:

 public function MyFunction(Request $request){

    $return = [];
    $return["success"] = true;
    $return["msg"] = "";

      //I run more functions

      session()->put('variable', $var);

     $return["success"] = true;
     $return["msg"] = "...";
    return $return;
    // or with response
    return new \Illuminate\Http\JsonResponse($return);

Sign in to participate in this thread!


Your banner here too?

Tomas Boo tomassbo Joined 7 Jun 2021


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.