weixin_33709609 2011-08-24 07:44 采纳率: 0%
浏览 24

自动更新网页内容

I am working on a system that has a bunch of sensors communicating with a linux machine. I need to make a web interface for this to display status of sensors and automatically update them when the status of any of the sensors changes(or just automatically update them every few seconds).

The code for reading sensors is all in C code. What are the options for pushing the sensor data to the web browser automatically or even by continuously requesting the data?

I have considered the following scheme: Allocate shared memory in the C program for the sensor data, which can be read by a server side script like php. Then have some ajax or something requesting the data on a loop or timer event.

Is it possible to push the data to the client rather than pull?

I really do not have any experience with php/ajax, so any tips on how to implement this would be great.

Some key elements I do not know:

-How to do timing in javascript

-How to get some sort of structured data in javascript on the fly from a request to the server(eg php page reading the sensor data)

  • 写回答

4条回答 默认 最新

  • weixin_33711641 2011-08-24 07:51
    关注
    1. You cannot generally push data using HTTP. You will have to poll the server. (There are alternatives that can push, if you are interested. See Comet)
    2. You can use Ajax to dynamically send request to the server. See this tutorial for details. It is pretty simple.
    3. You have to send this Ajax periodically. You can use setInterval for this.

    setTimeout("yourAjaxRequestFunction",delay);

    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用