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 ansys electronics 2021 R1安装报错,错误代码2,如图
  • ¥30 搭建面包板由NE555N和SN74LS90N组成的计时电路时出了问题
  • ¥15 无源定位系统的时差估计误差标准差
  • ¥15 请问这个代码哪里有问题啊
  • ¥20 python--version在命令端输入结果Python is not defined怎么办?还有pip不是exe格式是不是没安装成功?
  • ¥15 通过GaussianView进行结构微调消除虚频
  • ¥15 调用transformers库
  • ¥15 由于导出的数据名字中带有/,导致Matlab打不开,怎么办?
  • ¥15 新硬盘安装的程序总是崩溃,提示遇到错误
  • ¥15 openpcdet自制数据集评估bev精度和3d精度相同