duanfeng7756 2018-06-13 20:01
浏览 140
已采纳

Laravel - 使用AJAX实时显示ram和cpu使用情况

I am making a control panel in which a user can see their RAM and CPU usage. I made the Laravel part of the project and started on the bootstrap. So far I am displaying the usage using bootstrap:

<div class="progress">

  <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: {{$cpu}}%"></div>

</div>

I am retrieving the data in the Controller and then I am passing it to the view:

return view('control_panel', compact('cpu', 'ram'));

However, my problem is the user has to refresh the page constantly in order to get real time information. It is not such a big problem for now but in the future it may become a burden.

Is there a way to update the page automatically (every few seconds)? I worked a bit with jQuery but never with Ajax. Is there a simple solution to my problem?

  • 写回答

1条回答 默认 最新

  • dtzhfb4869 2018-06-14 00:55
    关注

    For best solution, you should use broadcasting. So You don't have to refresh page. You can send data with Scheduling every one minute and broadcast data. Then you can show this data on page.

    This is real time example project project with Laravel, Redis, Web socket and Laravel Echo Server

    https://github.com/durmus-aydogdu/real-time-application

    I hope this will help you.

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

报告相同问题?

悬赏问题

  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统
  • ¥15 快手联盟怎么快速的跑出建立模型