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

      • <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="qwawimqqmiuu" 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="qwawimqqmiuu" 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ì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我正在使用 HTML5 上傳文件.我有一個(gè)按鈕單擊事件附加到函數(shù) uploadFile().它工作正常.我還有一個(gè)單獨(dú)的按鈕來取消上傳.我知道我們需要調(diào)用 xhr.abort() 但如何訪問 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/

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

                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)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(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 無法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(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="qwawimqqmiuu" 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>
                          主站蜘蛛池模板: 影音先锋亚洲资源 | 日韩av一区在线观看 | 国产精品天堂 | 国产伦精品一区二区三区精品视频 | 亚洲一区三区在线观看 | 婷婷久久五月 | 亚洲欧美日韩精品 | 国产露脸国语对白在线 | 国产日韩一区二区 | 国产91丝袜在线18 | 欧美性吧 | 精品无码久久久久久国产 | 青青久久av北条麻妃海外网 | 亚洲国产欧美91 | 狠狠干影院 | 国产精品一区二区久久精品爱微奶 | 久久精品成人 | 亚洲精品国产a久久久久久 午夜影院网站 | 在线免费黄色小视频 | 亚洲成人高清 | 亚洲黄色网址视频 | 亚洲www.| 久视频在线 | 日本一区二区高清不卡 | 精品在线免费看 | 精品久久久久久久 | 羞羞的视频在线 | 亚洲欧美中文日韩在线v日本 | 黄色av大片 | 欧美激情国产日韩精品一区18 | 国产乱码精品一区二区三区忘忧草 | 亚洲精久久 | 成人超碰 | 欧美一区免费 | 少妇一级淫片aaaaaaaaa | 国产在线精品一区二区三区 | 中文字幕一区二区在线观看 | 91av视频在线 | 秋霞a级毛片在线看 | 91在线电影 | 涩爱av一区二区三区 |