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

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

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

    2. 中止 xmlhttprequest

      Aborting the xmlhttprequest(中止 xmlhttprequest)
        <bdo id='xOOKp'></bdo><ul id='xOOKp'></ul>
        <i id='xOOKp'><tr id='xOOKp'><dt id='xOOKp'><q id='xOOKp'><span id='xOOKp'><b id='xOOKp'><form id='xOOKp'><ins id='xOOKp'></ins><ul id='xOOKp'></ul><sub id='xOOKp'></sub></form><legend id='xOOKp'></legend><bdo id='xOOKp'><pre id='xOOKp'><center id='xOOKp'></center></pre></bdo></b><th id='xOOKp'></th></span></q></dt></tr></i><div class="85pc0be" id='xOOKp'><tfoot id='xOOKp'></tfoot><dl id='xOOKp'><fieldset id='xOOKp'></fieldset></dl></div>
          <tbody id='xOOKp'></tbody>

          <tfoot id='xOOKp'></tfoot>
            1. <small id='xOOKp'></small><noframes id='xOOKp'>

                <legend id='xOOKp'><style id='xOOKp'><dir id='xOOKp'><q id='xOOKp'></q></dir></style></legend>
                本文介紹了中止 xmlhttprequest的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我正在使用 HTML5 上傳文件.我有一個(gè)按鈕單擊事件附加到函數(shù) uploadFile().它工作正常.我還有一個(gè)單獨(dú)的按鈕來(lái)取消上傳.我知道我們需要調(diào)用 xhr.abort() 但如何訪問(wèn) uploadCanceled 函數(shù)中的 xhr 對(duì)象?我可以使 xhr 對(duì)象成為全局對(duì)象,但這不是正確的方法.有人可以在這里指導(dǎo)我嗎?

                I am using HTML5 for uploading files. I have a button click event attached to the function uploadFile(). It works fine. I also have a separate button to cancel the upload. I know we need to call xhr.abort() but how do I access the xhr object in the uploadCanceled function? I can make the xhr object global but that is not the proper way. Can someone guide me here?

                function uploadFile(){ 
                    var filesToBeUploaded = document.getElementById("fileControl"); 
                    var file = filesToBeUploaded.files[0]; 
                    var xhr= new XMLHttpRequest(); 
                    xhr.upload.addEventListener("progress", uploadProgress, false);
                    xhr.addEventListener("load", uploadComplete, false);
                    xhr.addEventListener("error", uploadFailed, false);
                    xhr.addEventListener("abort", uploadCanceled, false);
                
                
                    xhr.open("POST", "upload.php", true); 
                
                    var fd = new FormData();
                    fd.append("fileToUpload", file);
                     xhr.send(fd); 
                }
                
                
                    function uploadCanceled(evt) {
                        alert("Upload has been cancelled");
                    } 
                

                干杯

                推薦答案

                addEventListener 將設(shè)置 uploadCanceled 的上下文 (this) 為 <代碼>xhr:

                addEventListener will set the context (this) of uploadCanceled to xhr:

                function uploadCanceled(evt) {
                    console.log("Cancelled: " + this.status);
                }
                

                示例:http://jsfiddle.net/wJt8A/

                如果您需要通過(guò)取消"單擊觸發(fā) xhr.abort,則可以返回引用并在此之后添加所需的任何偵聽(tīng)器:

                If, instead, you need to trigger xhr.abort through a "Cancel" click, you can return a reference and add any listeners you need after that:

                function uploadFile() {
                    /* snip */
                    xhr.send(fd);
                
                    return xhr;
                }
                
                document.getElementById('submit').addEventListener('click', function () {
                    var xhr = uploadFile(),
                        submit = this,
                        cancel = document.getElementById('cancel');
                
                    function detach() {
                        // remove listeners after they become irrelevant
                        submit.removeEventListener('click', canceling, false);
                        cancel.removeEventListener('click', canceling, false);
                    }
                
                    function canceling() {
                        detach();
                        xhr.abort();
                    }
                
                    // detach handlers if XHR finishes first
                    xhr.addEventListener('load', detach, false);
                
                    // cancel if "Submit" is clicked again before XHR finishes
                    submit.addEventListener('click', canceling, false);
                
                    // and, of course, cancel if "Cancel" is clicked
                    cancel.addEventListener('click', canceling, false);
                }, false);
                

                示例:http://jsfiddle.net/rC63r/1/

                這篇關(guān)于中止 xmlhttprequest的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會(huì)等待 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 無(wú)法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開(kāi)發(fā)技術(shù)分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請(qǐng)求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)

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

                    • <tfoot id='lkMPS'></tfoot>
                        <tbody id='lkMPS'></tbody>

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

                        <legend id='lkMPS'><style id='lkMPS'><dir id='lkMPS'><q id='lkMPS'></q></dir></style></legend>
                          <bdo id='lkMPS'></bdo><ul id='lkMPS'></ul>
                          主站蜘蛛池模板: 岩棉板|岩棉复合板|聚氨酯夹芯板|岩棉夹芯板|彩钢夹芯板-江苏恒海钢结构 | 色谱柱-淋洗液罐-巴罗克试剂槽-巴氏吸管-5ml样品瓶-SBS液氮冻存管-上海希言科学仪器有限公司 | 广东教师资格网-广东教师资格证考试网| 冷凝锅炉_燃气锅炉_工业燃气锅炉改造厂家-北京科诺锅炉 | 恒温油槽-恒温水槽-低温恒温槽厂家-宁波科麦仪器有限公司 | 玻璃瓶厂家_酱菜瓶厂家_饮料瓶厂家_酒瓶厂家_玻璃杯厂家_徐州东明玻璃制品有限公司 | 智慧食堂_食堂管理系统_食堂订餐_食堂消费系统—客易捷 | 骨灰存放架|骨灰盒寄存架|骨灰架厂家|智慧殡葬|公墓陵园管理系统|网上祭奠|告别厅智能化-厦门慈愿科技 | 耐火浇注料-喷涂料-浇注料生产厂家_郑州市元领耐火材料有限公司 耐力板-PC阳光板-PC板-PC耐力板 - 嘉兴赢创实业有限公司 | 紫外荧光硫分析仪-硫含量分析仪-红外光度测定仪-泰州美旭仪器 | 电缆接头-防爆电缆接头-格兰头-金属电缆接头-防爆填料函 | 粉末冶金注射成型厂家|MIM厂家|粉末冶金齿轮|MIM零件-深圳市新泰兴精密科技 | 东莞喷砂机-喷砂机-喷砂机配件-喷砂器材-喷砂加工-东莞市协帆喷砂机械设备有限公司 | 电力测功机,电涡流测功机,磁粉制动器,南通远辰曳引机测试台 | 空气净化器租赁,空气净化器出租,全国直租_奥司汀净化器租赁 | SMC-SMC电磁阀-日本SMC气缸-SMC气动元件展示网 | 杭州中策电线|中策电缆|中策电线|杭州中策电缆|杭州中策电缆永通集团有限公司 | 数控走心机-走心机价格-双主轴走心机-宝宇百科 | 酒店品牌设计-酒店vi设计-酒店标识设计【国际级】VI策划公司 | 智能风向风速仪,风速告警仪,数字温湿仪,综合气象仪(气象五要素)-上海风云气象仪器有限公司 | 塑胶跑道施工-硅pu篮球场施工-塑胶网球场建造-丙烯酸球场材料厂家-奥茵 | 密集架|电动密集架|移动密集架|黑龙江档案密集架-大量现货厂家销售 | 减速机电机一体机_带电机减速器一套_德国BOSERL电动机与减速箱生产厂家 | 有声小说,听书,听小说资源库-听世界网 | 微水泥_硅藻泥_艺术涂料_艺术漆_艺术漆加盟-青岛泥之韵环保壁材 武汉EPS线条_EPS装饰线条_EPS构件_湖北博欧EPS线条厂家 | 首页|光催化反应器_平行反应仪_光化学反应仪-北京普林塞斯科技有限公司 | 沈阳楼承板_彩钢板_压型钢板厂家-辽宁中盛绿建钢品股份有限公司 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 喷漆房_废气处理设备-湖北天地鑫环保设备有限公司 | 牛皮纸|牛卡纸|进口牛皮纸|食品级牛皮纸|牛皮纸厂家-伽立实业 | 一点车讯-汽车网站,每天一点最新车讯! | 成都网站建设制作_高端网站设计公司「做网站送优化推广」 | 安规_综合测试仪,电器安全性能综合测试仪,低压母线槽安规综合测试仪-青岛合众电子有限公司 | 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 轴流风机-鼓风机-离心风机-散热风扇-罩极电机,生产厂家-首肯电子 | 沧州友城管业有限公司-内外涂塑钢管-大口径螺旋钢管-涂塑螺旋管-保温钢管生产厂家 | 冰雕-冰雪世界-大型冰雕展制作公司-赛北冰雕官网 | 超声骨密度仪,双能X射线骨密度仪【起草单位】,骨密度检测仪厂家 - 品源医疗(江苏)有限公司 | 一体式钢筋扫描仪-楼板测厚仪-裂缝检测仪-泰仕特(北京) | 游泳池设备安装工程_恒温泳池设备_儿童游泳池设备厂家_游泳池水处理设备-东莞市君达泳池设备有限公司 | 球形钽粉_球形钨粉_纳米粉末_难熔金属粉末-广东银纳官网 | 滑板场地施工_极限运动场地设计_滑板公园建造_盐城天人极限运动场地建设有限公司 |