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

tomassbo, davidningthoujam liked this thread

2
moderator

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);
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Tomas Boo tomassbo Joined 7 Jun 2021

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.