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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵