久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='vQ5e7'><style id='vQ5e7'><dir id='vQ5e7'><q id='vQ5e7'></q></dir></style></legend>

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

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

        <bdo id='vQ5e7'></bdo><ul id='vQ5e7'></ul>
    2. <tfoot id='vQ5e7'></tfoot>

      1. 如何強制程序等到 JavaScript 中的 HTTP 請求完成?

        How to force a program to wait until an HTTP request is finished in JavaScript?(如何強制程序等到 JavaScript 中的 HTTP 請求完成?)
        <legend id='adsqR'><style id='adsqR'><dir id='adsqR'><q id='adsqR'></q></dir></style></legend>

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

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

                <tbody id='adsqR'></tbody>

                <bdo id='adsqR'></bdo><ul id='adsqR'></ul>
                  <tfoot id='adsqR'></tfoot>
                  本文介紹了如何強制程序等到 JavaScript 中的 HTTP 請求完成?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在 JavaScript 中有沒有辦法向 HTTP 服務器發送 HTTP 請求并等待服務器響應?我希望我的程序等到服務器回復而不執行此請求之后的任何其他命令.如果 HTTP 服務器宕機了,我希望 HTTP 請求在超時后重復,直到服務器回復,然后程序的執行才能正常繼續.

                  Is there a way in JavaScript to send an HTTP request to an HTTP server and wait until the server responds with a reply? I want my program to wait until the server replies and not to execute any other command that is after this request. If the HTTP server is down I want the HTTP request to be repeated after a timeout until the server replies, and then the execution of the program can continue normally.

                  有什么想法嗎?

                  提前謝謝你,塔納西斯

                  推薦答案

                  XmlHttpRequestopen()有第三個參數,目的是表明你希望異步請求(因此通過 onreadystatechange 處理程序處理響應).

                  There is a 3rd parameter to XmlHttpRequest's open(), which aims to indicate that you want the request to by asynchronous (and so handle the response through an onreadystatechange handler).

                  因此,如果您希望它是同步的(即等待答案),只需將此第三個參數指定為 false.在這種情況下,您可能還想為您的請求設置一個有限的 timeout 屬性,因為它會阻塞頁面直到接收到.

                  So if you want it to be synchronous (i.e. wait for the answer), just specify false for this 3rd argument. You may also want to set a limited timeout property for your request in this case, as it would block the page until reception.

                  這是一個同步和異步的一體化示例函數:

                  Here is an all-in-one sample function for both sync and async:

                  function httpRequest(address, reqType, asyncProc) {
                    var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
                    if (asyncProc) { 
                      req.onreadystatechange = function() { 
                        if (this.readyState == 4) {
                          asyncProc(this);
                        } 
                      };
                    } else { 
                      req.timeout = 4000;  // Reduce default 2mn-like timeout to 4 s if synchronous
                    }
                    req.open(reqType, address, !(!asyncProc));
                    req.send();
                    return req;
                  }
                  

                  你可以這樣稱呼:

                  var req = httpRequest("http://example.com/aPageToTestForExistence.html", "HEAD");  // In this example you don't want to GET the full page contents
                  alert(req.status == 200 ? "found!" : "failed");  // We didn't provided an async proc so this will be executed after request completion only
                  

                  這篇關于如何強制程序等到 JavaScript 中的 HTTP 請求完成?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 部分內容)

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

                      <tbody id='PdcsC'></tbody>
                      • <bdo id='PdcsC'></bdo><ul id='PdcsC'></ul>
                        • <legend id='PdcsC'><style id='PdcsC'><dir id='PdcsC'><q id='PdcsC'></q></dir></style></legend>
                          <tfoot id='PdcsC'></tfoot>
                        • <i id='PdcsC'><tr id='PdcsC'><dt id='PdcsC'><q id='PdcsC'><span id='PdcsC'><b id='PdcsC'><form id='PdcsC'><ins id='PdcsC'></ins><ul id='PdcsC'></ul><sub id='PdcsC'></sub></form><legend id='PdcsC'></legend><bdo id='PdcsC'><pre id='PdcsC'><center id='PdcsC'></center></pre></bdo></b><th id='PdcsC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PdcsC'><tfoot id='PdcsC'></tfoot><dl id='PdcsC'><fieldset id='PdcsC'></fieldset></dl></div>

                          1. 主站蜘蛛池模板: 国产精品一区二区三区在线 | 国产分类视频 | 国产美女久久久 | 欧美一级特黄aaa大片在线观看 | www亚洲精品 | 亚洲色图第一页 | 一区二区三区国产精品 | 日韩2020狼一二三 | 久久成人免费 | 亚洲欧美激情视频 | 在线观看免费黄色片 | 国产亚洲精品久久久久动 | 国产在线中文 | 午夜精品久久久久久久久久久久久 | 午夜精品一区二区三区在线视 | 久久亚洲春色中文字幕久久久 | 日韩精品一区二区三区在线观看 | 国产美女福利在线观看 | 日韩高清在线观看 | 涩涩视频在线播放 | 久操国产 | 亚洲精品日韩在线 | 毛片区 | 久久新视频 | 一区二区三区四区电影视频在线观看 | 91精品国产91久久久 | 伊人啪啪网 | 日韩欧美电影在线 | 在线视频一区二区三区 | 久久精品国产一区 | av在线天天| 日韩视频一区在线观看 | 国产91在线 | 中日 | 日韩av免费在线电影 | 蜜桃av鲁一鲁一鲁一鲁 | 欧美一区二区三区在线观看视频 | 91久久精品国产 | 日韩看片 | 日韩视频在线免费观看 | 国产精品一区二区三区在线 | 欧美精品久久久久 |