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条)

报告相同问题?

悬赏问题

  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播