laravel 4 persisting data ongoing - jquery ajax submit

前端 未结 3 527
没有蜡笔的小新
没有蜡笔的小新 2020-12-16 07:16

I\'m having ongoing problems with laravel 4.1 sessions and getting unexpected behaviour.

Depending on how I call the controllers method the session either works or d

3条回答
  •  自闭症患者
    2020-12-16 08:07

    This is in reference to the solution that Ray gave. I had a very similar problem, which your solution resolved. Initially, I had the following on my Controller:

    echo json_encode(array('auth' => $auth));
    

    I changed this to:

    return Response::json(array('auth' => $auth));
    

    However, this was only part of the solution. In my javascript file, I initially had:

    data = $.parseJSON(data);
    

    Which, if I had kept the echo in the controller...would have been needed. apparently Laravel will do some magic behind the scenes when using Response::json() so that the data that is returned is already parsed. Removing that line in my javascript file made everything happy again :)

提交回复
热议问题