dtvfshi5248 2014-10-14 08:40
浏览 342
已采纳

Laravel Ajax和Session问题?

I have an ajax call which fires right when the DOM has finished loading, yet I am trying to prevent a situation when the user hits refresh and fires that ajax call again by storing a session variable. Yet, there seems to be an issue with storing a session entry via AJAX request, consider the following snippet:

<?php
function postMyAjax() {

$already_fired = \Session::get('ajax_fired'); // <-- Always returns NULL!
if ( ! empty( $already_fired ) ) {
    return Response::json(array('already fired'));
}

# Remember that we fired that call
\Session::put('ajax_fired',1); // <-- Fails to set?

return Response::json(array('ok'));

}

Any ideas?

  • 写回答

2条回答 默认 最新

  • douyiji3919 2016-02-23 18:27
    关注

    For the sake of answering the question, this has been a bug since laravel 4.1 where session handling becomes unstable with asynchronous requests.It is intensively being discussed here in github issues. My research points to the fact that basically, Laravel saves sessions in the last part of the request cycle and ajax/asynchronous requests processes differently as opposed to requests from browsers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料