如何使用AJAX读取实时流数据 [英] How to read Live streaming data using AJAX

查看:38
本文介绍了如何使用AJAX读取实时流数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的URL(即http://..)中读取实时流式传输数据我的URL(即http://..)包含数字数据,并且一直在增长.我想将该数据读入我的文件(HTML5和javascript).我已经使用AJAX处理了静态数值数据.但是,同时使用动态数据(实时流数据).我无法获得responseText().是否可以采用包含实时流数据的URL(即http://..)的responseText()?我该怎么做?我用于读取静态数据的代码是

I want to read live streaming data from my URL(ie.http://..) My URL(ie.http://..) contain numeric data and it's continuously growing. i want to read that data in to my file(HTML5 & javascript). I have done with static numeric data using AJAX. But while duing it with dynamic data(live streaming data). i am not able to get responseText(). Is it possible to take responseText() of that URL(ie.http://..) which contain live streaming data? how i can do this? My code for reading static data is

<!DOCTYPE HTML>
<html>
<head>    

<script type="text/javascript">
  function accessWebservice()
    {           
        var xmlhttp;
        xmlhttp = new XMLHttpRequest();

 //xmlhttp.open("get","http://192.168.15.174/Streamer/StartStream.aspx?IsTestData=true",true);   
 //above URL contains live streaming numberic data that i want to read
 //But when i am using above URL i am not getting responseText (**How to get it?**)
  xmlhttp.open("get","http://localhost/StaticDemoData.txt",true);   //This contains static data
        xmlhttp.onreadystatechange=function() {
         if (xmlhttp.readyState==4)
         {
             if (xmlhttp.status == 200 )
              {
                 var responseData=xmlhttp.responseText;
           alert(responseData);
              }
             else
             {
                 alert("Server returned: " + xmlhttp.status);
             }
         }
        }

        xmlhttp.send(null);
    }
</script>
</head>

如何获取用于实时流式传输数字数据的"xmlhttp.responseText"?

How to get 'xmlhttp.responseText' for live streaming numeric data?

推荐答案

如果您检查 xmlhttp.readyState == 3 (XMLHttpRequest.LOADING),然后访问 xmlhttp.responseText 会为您提供到目前为止从服务器接收到的数据.然后,您可以使用setInterval不断检查 xmlhttp.responseText 中的新数据.

If you check for xmlhttp.readyState == 3 (XMLHttpRequest.LOADING), then accessing xmlhttp.responseText will give you the data that has been received from your server so far. You can then use a setInterval to constantly check xmlhttp.responseText for new data.

这篇关于如何使用AJAX读取实时流数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆