dream12001 2016-05-04 05:36
浏览 59

Laravel Ajax调用删除会话闪存数据

My repeated Ajax call deletes session flash data

I have a Javascript to make an Ajax call it calls my api every 5 seconds to update my user page.

I am returning a view with flash data which it has to keep for the next request but the Ajax call clears it and the next request is not completed.

Is there a way to complete it?

I can think to re-flash on an api call, but that seems weird. Any other way?

  • 写回答

1条回答 默认 最新

  • doubang4881 2016-05-04 06:16

    Since your ajax call needs access to the session information, you have to load the session, which will count as your access to the flash data. You will need your ajax call to reflash the data.

    There is a reflash method on the session that will take care of this for you. You can either call it in the Controller method that handles your ajax call, or better yet, create a new middleware that reflashes session data, and attach the middleware to any route that needs this functionality.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥15 我需要在PC端 开两个抖店工作台客户端.(语言-java)
    • ¥15 有没有哪位厉害的人可以用C#可视化呀
    • ¥15 可以帮我看看代码哪里错了吗
    • ¥15 设计一个成绩管理系统
    • ¥15 PCL注册的选点等函数如何取消注册
    • ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
    • ¥15 Python爬虫程序
    • ¥15 crypto 这种的应该怎么找flag?
    • ¥15 代码已写好,求帮我指出错误,有偿!
    • ¥15 matlab+波形匹配算法