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?

图片转代码服务由CSDN问答提供 功能建议


我有一个Javascript到 做一个Ajax调用它每隔5秒调用我的api来更新我的用户页面。

我正在返回一个带有flash数据的视图,它必须为下一个请求保留,但是Ajax调用会清除 它和下一个请求没有完成。


我可以考虑在api通话时重新刷新 ,但这似乎很奇怪。 还有其他方式吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    打赏 评论

相关推荐 更多相似问题