pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <legend id='yLssG'><style id='yLssG'><dir id='yLssG'><q id='yLssG'></q></dir></style></legend>

      <small id='yLssG'></small><noframes id='yLssG'>

    1. <i id='yLssG'><tr id='yLssG'><dt id='yLssG'><q id='yLssG'><span id='yLssG'><b id='yLssG'><form id='yLssG'><ins id='yLssG'></ins><ul id='yLssG'></ul><sub id='yLssG'></sub></form><legend id='yLssG'></legend><bdo id='yLssG'><pre id='yLssG'><center id='yLssG'></center></pre></bdo></b><th id='yLssG'></th></span></q></dt></tr></i><div class="j7zz5jd" id='yLssG'><tfoot id='yLssG'></tfoot><dl id='yLssG'><fieldset id='yLssG'></fieldset></dl></div>
        <bdo id='yLssG'></bdo><ul id='yLssG'></ul>

    2. <tfoot id='yLssG'></tfoot>

      1. “HTTP Streaming"的跨瀏覽器實現(推)AJAX 模式

        Cross-browser implementation of quot;HTTP Streamingquot; (push) AJAX pattern(“HTTP Streaming的跨瀏覽器實現(推)AJAX 模式)
        • <i id='Znejg'><tr id='Znejg'><dt id='Znejg'><q id='Znejg'><span id='Znejg'><b id='Znejg'><form id='Znejg'><ins id='Znejg'></ins><ul id='Znejg'></ul><sub id='Znejg'></sub></form><legend id='Znejg'></legend><bdo id='Znejg'><pre id='Znejg'><center id='Znejg'></center></pre></bdo></b><th id='Znejg'></th></span></q></dt></tr></i><div class="xdjjpjn" id='Znejg'><tfoot id='Znejg'></tfoot><dl id='Znejg'><fieldset id='Znejg'></fieldset></dl></div>
            <tbody id='Znejg'></tbody>

        • <legend id='Znejg'><style id='Znejg'><dir id='Znejg'><q id='Znejg'></q></dir></style></legend>

        • <tfoot id='Znejg'></tfoot>

          <small id='Znejg'></small><noframes id='Znejg'>

              <bdo id='Znejg'></bdo><ul id='Znejg'></ul>

                1. 本文介紹了“HTTP Streaming"的跨瀏覽器實現(推)AJAX 模式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  客戶端從服務器請求網頁.然后 Clent 要求進行額外的計算;服務器執行一系列計算并在部分結果可用時立即發送(文本格式,每行包含單獨的完整項目).客戶端使用服務器提供的信息更新網頁(使用 JavaScript 和 DOM).

                  Client request web page from server. Clent then requests for extra calculations to be done; server performs series of calculations and sends partial results as soon as they are available (text format, each line contains separate full item). Client updates web page (with JavaScript and DOM) using information provided by server.

                  這似乎適合 HTTP Streaming (當前 版本)模式來自 Ajaxpatterns 站點.

                  This seems to fit HTTP Streaming (current version) pattern from Ajaxpatterns site.

                  問題是如何以跨瀏覽器(與瀏覽器無關)的方式進行,最好不使用 JavaScript 框架,或使用一些輕量級框架,如 jQuery.

                  The question is how to do it in cross-browser (browser agnostic) way, preferably without using JavaScript frameworks, or using some lightweight framework like jQuery.

                  問題始于以跨瀏覽器方式生成 XMLHttpRequest,但我認為主要是并非所有瀏覽器都能正確實現 onreadystatechangefrom XMLHttpRequest;并非所有瀏覽器都會在每次服務器刷新時調用 onreadystatechange 事件(順便說一句.如何從 CGI 腳本(在 Perl 中)強制服務器刷新?).Ajaxpatterns 上的示例代碼通過使用計時器來處理這個問題;如果我檢測到來自 onreadystatechange 的部分響應,我應該放棄計時器解決方案嗎?

                  The problem begins with generating XMLHttpRequest in cross-browser fashion, but I think the main item is that not all browsers implement correctly onreadystatechangefrom XMLHttpRequest; not all browsers call onreadystatechange event on each server flush (BTW. how to force server flush from within CGI script (in Perl)?). Example code on Ajaxpatterns deals with this by using timer; should I drop timer solution if I detect partial response from onreadystatechange?

                  添加于 2009 年 8 月 11 日

                  當前解決方案:
                  我使用以下函數創建 XMLHttpRequest 對象:

                  Current solution:
                  I use the following function to create XMLHttpRequest object:

                  function createRequestObject() {
                          var ro;
                          if (window.XMLHttpRequest) {
                                  ro = new XMLHttpRequest();
                          } else {
                                  ro = new ActiveXObject("Microsoft.XMLHTTP");
                          }
                          if (!ro)
                                  debug("Couldn't start XMLHttpRequest object");
                          return ro;
                  }
                  

                  如果我要使用一些(最好是輕量級的)JavaScript 框架,比如 jQuery,如果用戶選擇不安裝 jQuery,我希望有備用.

                  If I were to use some (preferably light-weight) JavaScript framework like jQuery, I'd like to have fallback if user chooses not to install jQuery.

                  我使用下面的代碼來啟動 AJAX;使用 setInterval 是因為某些瀏覽器僅在服務器關閉連接后(可能需要數十秒)才調用 onreadystatechange,而不是在服務器刷新數據時(大約每第二次或更頻繁).

                  I use the following code to start AJAX; setInterval is used because some browsers call onreadystatechange only after server closes connection (which can take as long as tens of seconds), and not as soon as server flushes data (around every second or more often).

                  function startProcess(dataUrl) {
                          http = createRequestObject();
                          http.open('get', dataUrl);
                          http.onreadystatechange = handleResponse;
                          http.send(null);
                  
                          pollTimer = setInterval(handleResponse, 1000);
                  }
                  

                  handleResponse 函數是最復雜的一個,但它的草圖如下所示.可以做得更好嗎?如何使用一些輕量級的 JavaScript 框架(如 jQuery)來完成?

                  The handleResponse function is most complicated one, but the sketch of it looks like the following. Can it be done better? How it would be done using some lightweight JavaScript framework (like jQuery)?

                  function handleResponse() {
                      if (http.readyState != 4 && http.readyState != 3)
                          return;
                      if (http.readyState == 3 && http.status != 200)
                          return;
                      if (http.readyState == 4 && http.status != 200) {
                          clearInterval(pollTimer);
                          inProgress = false;
                      }
                      // In konqueror http.responseText is sometimes null here...
                      if (http.responseText === null)
                          return;
                  
                      while (prevDataLength != http.responseText.length) {
                          if (http.readyState == 4  && prevDataLength == http.responseText.length)
                              break;
                          prevDataLength = http.responseText.length;
                          var response = http.responseText.substring(nextLine);
                          var lines = response.split('
                  ');
                          nextLine = nextLine + response.lastIndexOf('
                  ') + 1;
                          if (response[response.length-1] != '
                  ')
                              lines.pop();
                  
                          for (var i = 0; i < lines.length; i++) {
                              // ...
                          }
                      }
                  
                      if (http.readyState == 4 && prevDataLength == http.responseText.length)
                          clearInterval(pollTimer);
                  
                      inProgress = false;
                  }
                  

                  推薦答案

                  實際上,您鏈接到的解決方案根本不是 AJAX.他們稱之為 HTTP 流,但它本質上只是長輪詢.

                  The solution you linked to is not AJAX at all, actually. They call it HTTP Streaming but it's essentially just long polling.

                  在他們鏈接到的示例中,您可以很容易地使用 firebug 自己查看.打開網絡面板 - 沒有 XHR 條目,但加載原始頁面只需 10 多秒.那是因為他們在幕后使用 PHP 來延遲 HTML 的輸出.這就是長輪詢的本質——HTTP 連接保持打開狀態,周期性的 HTML 發回是 javascript 命令.

                  In the example they link to, you can see for yourself quite easily with firebug. Turn on the Net panel - there are no XHR entries, but it takes just a hair over 10 seconds to load the original page. That's because they're using PHP behind the scenes to delay the output of the HTML. This is the essence of long polling - the HTTP connection stays open, and the periodic HTML sent back is javascript commands.

                  不過,您可以選擇使用 setTimeout() 或 setInterval() 在客戶端完全進行輪詢

                  You can opt to do the polling completely on the client side, though, with setTimeout() or setInterval()

                  一個 jQuery 示例

                  A jQuery example

                  <script type="text/javascript">
                    $(document).ready(function()
                    {
                      var ajaxInterval = setInterval( function()
                      {
                        $.getJSON(
                          'some/servie/url.ext'
                          , { sample: "data" }
                          , function( response )
                            {
                              $('#output').append( response.whatever );          
                            }
                        );
                      }, 10000 );  
                    });
                  </script>
                  

                  這篇關于“HTTP Streaming"的跨瀏覽器實現(推)AJAX 模式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                    <bdo id='977Wm'></bdo><ul id='977Wm'></ul>
                  • <legend id='977Wm'><style id='977Wm'><dir id='977Wm'><q id='977Wm'></q></dir></style></legend>
                      • <i id='977Wm'><tr id='977Wm'><dt id='977Wm'><q id='977Wm'><span id='977Wm'><b id='977Wm'><form id='977Wm'><ins id='977Wm'></ins><ul id='977Wm'></ul><sub id='977Wm'></sub></form><legend id='977Wm'></legend><bdo id='977Wm'><pre id='977Wm'><center id='977Wm'></center></pre></bdo></b><th id='977Wm'></th></span></q></dt></tr></i><div class="txtdhpr" id='977Wm'><tfoot id='977Wm'></tfoot><dl id='977Wm'><fieldset id='977Wm'></fieldset></dl></div>
                          <tbody id='977Wm'></tbody>
                        <tfoot id='977Wm'></tfoot>

                          <small id='977Wm'></small><noframes id='977Wm'>

                          1. 主站蜘蛛池模板: 扬尘在线监测系统_工地噪声扬尘检测仪_扬尘监测系统_贝塔射线扬尘监测设备「风途物联网科技」 | 液氮罐_液氮容器_自增压液氮罐_杜瓦瓶_班德液氮罐厂家 | 亚克力制品定制,上海嘉定有机玻璃加工制作生产厂家—官网 | 乐考网-银行从业_基金从业资格考试_初级/中级会计报名时间_中级经济师 | 北钻固控设备|石油钻采设备-石油固控设备厂家 | 化工ERP软件_化工新材料ERP系统_化工新材料MES软件_MES系统-广东顺景软件科技有限公司 | 电动手术床,医用护理床,led手术无影灯-曲阜明辉医疗设备有限公司 | 中空玻璃生产线,玻璃加工设备,全自动封胶线,铝条折弯机,双组份打胶机,丁基胶/卧式/立式全自动涂布机,玻璃设备-山东昌盛数控设备有限公司 | 驾驶人在线_专业学车门户网站 | 污水提升器,污水提升泵,污水提升装置-德国泽德(zehnder)水泵系统有限公司 | 耐压仪-高压耐压仪|徐吉电气 | 热工多功能信号校验仪-热电阻热电偶校验仿真仪-金湖虹润仪表 | 新能源汽车教学设备厂家报价[汽车教学设备运营18年]-恒信教具 | 骨密度仪-骨密度测定仪-超声骨密度仪-骨龄测定仪-天津开发区圣鸿医疗器械有限公司 | 依维柯自动挡房车,自行式国产改装房车,小型房车价格,中国十大房车品牌_南京拓锐斯特房车 - 南京拓锐斯特房车 | 钢板仓,大型钢板仓,钢板库,大型钢板库,粉煤灰钢板仓,螺旋钢板仓,螺旋卷板仓,骨料钢板仓 | 真石漆,山东真石漆,真石漆厂家,真石漆价格-山东新佳涂料有限公司 | 液压中心架,数控中心架,自定心中心架-烟台恒阳机电设计有限公司 行星搅拌机,双行星搅拌机,动力混合机,无锡米克斯行星搅拌机生产厂家 | 百度爱采购运营研究社社群-店铺托管-爱采购代运营-良言多米网络公司 | 污水处理设备维修_污水处理工程改造_机械格栅_过滤设备_气浮设备_刮吸泥机_污泥浓缩罐_污水处理设备_污水处理工程-北京龙泉新禹科技有限公司 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 土壤有机碳消解器-石油|表层油类分析采水器-青岛溯源环保设备有限公司 | 品牌设计_VI设计_电影海报设计_包装设计_LOGO设计-Bacross新越品牌顾问 | 橡胶电子拉力机-塑料-微电脑电子拉力试验机厂家-江苏天源 | 烟雾净化器-滤筒除尘器-防爆除尘器-除尘器厂家-东莞执信环保科技有限公司 | EPDM密封胶条-EPDM密封垫片-EPDM生产厂家 | 智能汉显全自动量热仪_微机全自动胶质层指数测定仪-鹤壁市科达仪器仪表有限公司 | 广州企亚 - 数码直喷、白墨印花、源头厂家、透气无手感方案服务商! | 全自动翻转振荡器-浸出式水平振荡器厂家-土壤干燥箱价格-常州普天仪器 | 湖南成人高考报名-湖南成考网 | 东莞螺杆空压机_永磁变频空压机_节能空压机_空压机工厂批发_深圳螺杆空压机_广州螺杆空压机_东莞空压机_空压机批发_东莞空压机工厂批发_东莞市文颖设备科技有限公司 | 贵州水玻璃_-贵阳花溪闽兴水玻璃厂| ISO9001认证咨询_iso9001企业认证代理机构_14001|18001|16949|50430认证-艾世欧认证网 | 红酒招商加盟-葡萄酒加盟-进口红酒代理-青岛枞木酒业有限公司 | C形臂_动态平板DR_动态平板胃肠机生产厂家制造商-普爱医疗 | 致胜管家软件服务【在线免费体验】| 缠绕机|缠绕膜包装机|缠绕包装机-上海晏陵智能设备有限公司 | 微信小程序定制,广州app公众号商城网站开发公司-广东锋火 | 恒温油槽-恒温水槽-低温恒温槽厂家-宁波科麦仪器有限公司 | 天一线缆邯郸有限公司_煤矿用电缆厂家_矿用光缆厂家_矿用控制电缆_矿用通信电缆-天一线缆邯郸有限公司 | 房车价格_依维柯/大通/东风御风/福特全顺/江铃图片_云梯搬家车厂家-程力专用汽车股份有限公司 |