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

  • <small id='55GVD'></small><noframes id='55GVD'>

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

      <legend id='55GVD'><style id='55GVD'><dir id='55GVD'><q id='55GVD'></q></dir></style></legend>
      1. XMLHttpRequest 異步不起作用,總是返回狀態(tài) 0

        XMLHttpRequest asynchronous not working, always returns status 0(XMLHttpRequest 異步不起作用,總是返回狀態(tài) 0)
      2. <legend id='evyst'><style id='evyst'><dir id='evyst'><q id='evyst'></q></dir></style></legend>
          <tbody id='evyst'></tbody>
      3. <tfoot id='evyst'></tfoot>

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

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

            • <bdo id='evyst'></bdo><ul id='evyst'></ul>

                • 本文介紹了XMLHttpRequest 異步不起作用,總是返回狀態(tài) 0的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  這是我從 w3schools 拼湊的 XMLHttpRequest 示例

                  Here's a sample XMLHttpRequest I cobbled together from w3schools

                  <html>
                  <head>
                  <script type="text/javascript">
                  function loadXMLDoc()
                  {
                    var T="nothing";
                  
                    xmlhttp=new XMLHttpRequest();
                    xmlhttp.overrideMimeType('text/plain');  // don't sc
                    xmlhttp.onreadystatechange=function()
                    {
                      alert ("rdystate: " + xmlhttp.readyState);
                      alert ("status: "   + xmlhttp.status);
                      alert ("Text: "     + xmlhttp.statusText);
                      if (xmlhttp.readyState==4 && xmlhttp.status==200)
                      {
                        T = xmlhttp.responseText;
                      }
                    }
                  xmlhttp.open("GET","SBL_PROBES.htm",true);
                  xmlhttp.send(null);
                  //T = xmlhttp.responseText;
                  alert(T);
                  }
                  </script>
                  </head>
                  <body>
                  
                  <h2>Using the XMLHttpRequest object</h2>
                  <div id="myDiv"></div>
                  <button type="button" onclick="loadXMLDoc()">CHange Content</button>
                  
                  </body>
                  </html>
                  

                  XMLHttpRequest 始終返回零狀態(tài).

                  XMLHttpRequest always returns a zero status.

                  Firefox 的錯(cuò)誤控制臺中沒有顯示任何內(nèi)容.

                  Nothing shows up in Firefox's error console.

                  如果我通過更改行將請求更改為同步請求

                  If I change the request to synchronous one by changing the line

                  xmlhttp.open("GET","SBL_PROBES.htm",true);
                  

                  xmlhttp.open("GET","SBL_PROBES.htm",false);
                  

                  并取消注釋該行

                  //T = xmlhttp.responseText;
                  

                  返回請求文件的文本.

                  HTM 和文件位于同一目錄中.如果你嘗試這個(gè),你還需要一個(gè)文件 SBL_PROBES.htm,它的內(nèi)容是無關(guān)緊要的.

                  The HTM and the file reside in the same directory. If you try this you will need a file SBL_PROBES.htm there also, it's contents are irrelevant.

                  我使用的是 Firefox 3.6.22.

                  I'm using Firefox 3.6.22.

                  這可能是跨域問題嗎?如果是這樣,為什么它作為同步請求工作?

                  Could this be a cross domain problem? If so, why does it work as a synchronous request?

                  推薦答案

                  您可以在 if 語句中使用函數(shù).該函數(shù)在readystate變?yōu)?時(shí)執(zhí)行.

                  You can use a function inside the if statement. This function is executed when readystate changes to 4.

                  var handleResponse = function (status, response) {
                     alert(response)
                  }
                  var handleStateChange = function () {
                     switch (xmlhttp.readyState) {
                        case 0 : // UNINITIALIZED
                        case 1 : // LOADING
                        case 2 : // LOADED
                        case 3 : // INTERACTIVE
                        break;
                        case 4 : // COMPLETED
                        handleResponse(xmlhttp.status, xmlhttp.responseText);
                        break;
                        default: alert("error");
                     }
                  }
                  var xmlhttp=new XMLHttpRequest();
                  xmlhttp.onreadystatechange=handleStateChange;
                  xmlhttp.open("GET","SBL_PROBES.htm",true);
                  xmlhttp.send(null);
                  

                  您的舊代碼執(zhí)行了異步調(diào)用,并僅使用 alert 語句繼續(xù).此時(shí) T 為空.

                  Your old code did a asynchronous call and continued just with the alert Statement. T was empty at this time.

                  好的,我會稍微解釋一下整個(gè)過程是如何工作的:

                  Ok, I'll explain a little bit how this whole thing works:

                  首先我們定義兩個(gè)回調(diào)函數(shù),我們稍后在請求中調(diào)用它們,命名為handleResponse 和handleStateChange.

                  First we define two callback functions, which we call later in the request, named handleResponse and handleStateChange.

                  然后我們創(chuàng)建一個(gè)對象,它代表 XMLHttpRequest

                  Afterwards we create a Object, which represents the XMLHttpRequest

                  var xmlhttp=new XMLHttpRequest();
                  

                  這會產(chǎn)生如下的對象(簡化):

                  This results in an Object as follows (simplyfied):

                  XMLHttpRequest { status=0, readyState=0, multipart=false, onreadystatechange=handleEvent()}
                  

                  使用 open(...) 函數(shù)調(diào)用,您可以為請求設(shè)置參數(shù):

                  With the open(...) function call you set parameters for the request:

                  xmlhttp.open("GET","SBL_PROBES.htm",true);
                  

                  這意味著,執(zhí)行異步 GET 請求來獲取頁面 SBL_PROBES.htm然后調(diào)用 send(...) 函數(shù)來觸發(fā)請求本身.

                  This means, do a asynchronous GET Request to fetch the Page SBL_PROBES.htm Then the send(...) function is called which fires the request itself.

                  我們?yōu)閛nreadystatechange注冊了一個(gè)回調(diào)函數(shù),可以想象,這實(shí)際上是一個(gè)eventHandler.每次狀態(tài)改變時(shí)都會調(diào)用這個(gè)函數(shù).(這就像你在表單中注冊一個(gè)回調(diào)函數(shù)到一個(gè)onKeyUp事件一樣,每次你的key上升時(shí)都會觸發(fā)這個(gè)回調(diào):))

                  We registered a callback function for the onreadystatechange, as you can imagine, this is actually an eventHandler. Each time the state changes this function is called. (It is the same as if you register a callback function to an onKeyUp Event in a form, this callback is triggered each time your key goes up :) )

                  對您的問題感興趣的唯一情況是狀態(tài) 4.因此,僅在狀態(tài) 4 中調(diào)用 handleRequest 回調(diào)函數(shù).此時(shí)您的 Request 實(shí)際上有一個(gè)結(jié)果,還有一個(gè)狀態(tài).(狀態(tài)表示您的網(wǎng)絡(luò)服務(wù)器返回狀態(tài)代碼 200=ok、404=not found 等)

                  The only case which is of interest for your problem is state 4. Therefor the handleRequest callback function is called only in state 4. At this time you Request has actually a result, and further a status. (Status means your webserver returned a status code 200=ok, 404=not found etc.)

                  這并不是 ajax 背后的全部魔力,但應(yīng)該為您提供一個(gè)簡化的概述,即幕后實(shí)際發(fā)生的事情.請務(wù)必在網(wǎng)絡(luò)服務(wù)器上進(jìn)行測試,不要使用 file://進(jìn)行測試.

                  That is not all the magic which is behind the ajax stuff, but should give you a simplified overview, what is actually happening behind the scenes. It is important that you test this on a webserver, do not use file:// for testing.

                  如果您需要更多詳細(xì)信息,請告訴我.

                  If you need more in detail info, just let me know.

                  這篇關(guān)于XMLHttpRequest 異步不起作用,總是返回狀態(tài) 0的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調(diào)用完成)
                  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標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                  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 部分內(nèi)容)
                    <tbody id='zByYe'></tbody>

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

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

                            <bdo id='zByYe'></bdo><ul id='zByYe'></ul>
                            <tfoot id='zByYe'></tfoot>

                            <legend id='zByYe'><style id='zByYe'><dir id='zByYe'><q id='zByYe'></q></dir></style></legend>
                            主站蜘蛛池模板: 生物制药洁净车间-GMP车间净化工程-食品净化厂房-杭州波涛净化设备工程有限公司 | 华中线缆有限公司-电缆厂|电缆厂家|电线电缆厂家 | 派克防爆伺服电机品牌|国产防爆伺服电机|高低温伺服电机|杭州摩森机电科技有限公司 | 广州昊至泉水上乐园设备有限公司 | HDPE储罐_厂家-山东九州阿丽贝防腐设备 | 学考网学历中心| SOUNDWELL 编码器|电位器|旋转编码器|可调电位器|编码开关厂家-广东升威电子制品有限公司 | 纯水电导率测定仪-万用气体检测仪-低钠测定仪-米沃奇科技(北京)有限公司www.milwaukeeinst.cn 锂辉石检测仪器,水泥成分快速分析仪-湘潭宇科分析仪器有限公司 手术室净化装修-手术室净化工程公司-华锐手术室净化厂家 | 信阳网站建设专家-信阳时代网联-【信阳网站建设百度推广优质服务提供商】信阳网站建设|信阳网络公司|信阳网络营销推广 | 合肥弱电工程_安徽安防工程_智能化工程公司-合肥雷润 | 稳尚教育加盟-打造高考志愿填报平台_新高考志愿填报加盟_学业生涯规划加盟 | 穿线管|波纹穿线管|包塑金属软管|蛇皮管?闵彬专注弱电工程? | bng防爆挠性连接管-定做金属防爆挠性管-依客思防爆科技 | 实验室隔膜泵-无油防腐蚀隔膜泵-耐腐蚀隔膜真空泵-杭州景程仪器 电杆荷载挠度测试仪-电杆荷载位移-管桩测试仪-北京绿野创能机电设备有限公司 | TYPE-C厂家|TYPE-C接口|TYPE-C防水母座|TYPE-C贴片-深圳步步精 | 有机肥设备生产制造厂家,BB掺混肥搅拌机、复合肥设备生产线,有机肥料全部加工设备多少钱,对辊挤压造粒机,有机肥造粒设备 -- 郑州程翔重工机械有限公司 | 定制/定做衬衫厂家/公司-衬衫订做/订制价格/费用-北京圣达信 | 禹城彩钢厂_钢结构板房_彩钢复合板-禹城泰瑞彩钢复合板加工厂 | 大型多片锯,圆木多片锯,方木多片锯,板材多片锯-祥富机械有限公司 | 杭州高温泵_热水泵_高温油泵|昆山奥兰克泵业制造有限公司 | 彼得逊采泥器-定深式采泥器-电动土壤采样器-土壤样品风干机-常州索奥仪器制造有限公司 | 预制直埋蒸汽保温管-直埋管道-聚氨酯发泡保温管厂家 - 唐山市吉祥保温工贸有限公司 | 安全光栅|射频导纳物位开关|音叉料位计|雷达液位计|两级跑偏开关|双向拉绳开关-山东卓信机械有限公司 | 成都珞石机械 - 模温机、油温机、油加热器生产厂家 | 协议书_协议合同格式模板范本大全| 耐高温风管_耐高温软管_食品级软管_吸尘管_钢丝软管_卫生级软管_塑料波纹管-东莞市鑫翔宇软管有限公司 | 南京PVC快速门厂家南京快速卷帘门_南京pvc快速门_世界500强企业国内供应商_南京美高门业 | 钢骨架轻型板_膨石轻型板_钢骨架轻型板价格_恒道新材料 | 瑞典Blueair空气净化器租赁服务中心-专注新装修办公室除醛去异味服务! | 空压机商城|空气压缩机|空压机配件-压缩机网旗下商城 | 智能电表|预付费ic卡水电表|nb智能无线远传载波电表-福建百悦信息科技有限公司 | 智能家居全屋智能系统多少钱一套-小米全套价格、装修方案 | 小程序开发公司-小程序制作-微信小程序开发-小程序定制-咏熠软件 | 活性氧化铝球|氧化铝干燥剂|分子筛干燥剂|氢氧化铝粉-淄博同心材料有限公司 | CNC机加工-数控加工-精密零件加工-ISO认证厂家-鑫创盟 | 泰兴市热钻机械有限公司-热熔钻孔机-数控热熔钻-热熔钻孔攻牙一体机 | 防渗膜厂家|养殖防渗膜|水产养殖防渗膜-泰安佳路通工程材料有限公司 | 品牌策划-品牌设计-济南之式传媒广告有限公司官网-提供品牌整合丨影视创意丨公关活动丨数字营销丨自媒体运营丨数字营销 | 旋振筛|圆形摇摆筛|直线振动筛|滚筒筛|压榨机|河南天众机械设备有限公司 | 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | 酒吧霸屏软件_酒吧霸屏系统,酒吧微上墙,夜场霸屏软件,酒吧点歌软件,酒吧互动游戏,酒吧大屏幕软件系统下载 |