laravel 4 persisting data ongoing - jquery ajax submit

前端 未结 3 537
没有蜡笔的小新
没有蜡笔的小新 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 07:48

    Success!

    I found a similar problem relating to laravel 3. For the session to persist in an ajax call I need to return the response correctly.

    return json_encode($response);
    

    This is causing the problem. It's not it appears a valid response to enable the session to persist. I changed it to:

    return Response::json($response); 
    

    This enabled the session to persist!

    For some reason a normal form submit or call to the method allows the first one but ajax does not.

    I've seen references elsewhere about echo statements in the method affecting the session data but did not think I had any - the return I suppose must behaving similar to an echo

    Happy now (till the next problem)

    This is the post that triggered the solution: http://forumsarchive.laravel.io/viewtopic.php?id=1304

提交回复
热议问题