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>


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?

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

我正在创建一个控制面板,用户可以在其中查看其RAM和CPU使用情况。 我让Laravel成为项目的一部分并开始使用引导程序。 到目前为止,我正在使用bootstrap显示用法:</ p>

 &lt; div class =“progress”&gt; 
&lt; div class =“progress-bar progress-bar  -striped progress-bar-animated“role =”progressbar“style =”width:{{$ cpu}}%“&gt;&lt; / div&gt; 
&lt; / div&gt; 
 </ code> </ pre  > 

我正在检索Controller中的数据,然后将其传递给视图:</ p>

 返回视图('control_panel',compact('  cpu','ram')); 
 </ code> </ pre> 

但是,我的问题是用户必须不断刷新页面才能获得实时信息。 它现在不是一个大问题,但将来可能会成为负担。 </ p>

有没有办法自动更新页面(每隔几秒钟)? 我使用jQuery但从未使用过Ajax。 我的问题有一个简单的解决方案吗?</ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题