Auto-Refresh Div in Jade Template (Node.js/Express)

佐手、 提交于 2019-12-04 20:45:05

This can be done with jquery and ajax using the load() function.

<div id="myid"/>

$("#myid").load("a/path")

The data returned by a/path will be stored inside the div. To fetch the data you poll the server every second or use websockets and push the data directly from the server to the client.

Typically you would do this with a client-side ajax call and update your info in the dom. I recommend using jQuery:

<ul id="list"></ul>

$.get('/api/data', function(data){

 var htm = (
  '<li>'+data.foo+'</li>';
 );

 $("#list").append( htm );
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!