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

<tfoot id='XyXYp'></tfoot>

      • <bdo id='XyXYp'></bdo><ul id='XyXYp'></ul>
      <legend id='XyXYp'><style id='XyXYp'><dir id='XyXYp'><q id='XyXYp'></q></dir></style></legend>

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

      將 XMLhttpRequest 變成函數失敗:異步還是其他?

      Turn XMLhttpRequest into a function fails: asynchronity or other?(將 XMLhttpRequest 變成函數失敗:異步還是其他?)
      <tfoot id='Ji8Nc'></tfoot>
        <i id='Ji8Nc'><tr id='Ji8Nc'><dt id='Ji8Nc'><q id='Ji8Nc'><span id='Ji8Nc'><b id='Ji8Nc'><form id='Ji8Nc'><ins id='Ji8Nc'></ins><ul id='Ji8Nc'></ul><sub id='Ji8Nc'></sub></form><legend id='Ji8Nc'></legend><bdo id='Ji8Nc'><pre id='Ji8Nc'><center id='Ji8Nc'></center></pre></bdo></b><th id='Ji8Nc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Ji8Nc'><tfoot id='Ji8Nc'></tfoot><dl id='Ji8Nc'><fieldset id='Ji8Nc'></fieldset></dl></div>
            <tbody id='Ji8Nc'></tbody>

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

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

            • <small id='Ji8Nc'></small><noframes id='Ji8Nc'>

              • 本文介紹了將 XMLhttpRequest 變成函數失敗:異步還是其他?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我嘗試將 XMLHttpRequest 變成這樣的函數

                I try to turn an XMLHttpRequest into a function such

                var getImageBase64 = function (url) { // code function
                    var xhr = new XMLHttpRequest(url); 
                    ... // code to load file 
                    ... // code to convert data to base64
                    return wanted_result; // return result of conversion
                }
                var newData = getImageBase64('http://fiddle.jshell.net/img/logo.png'); // function call
                doSomethingWithData($("#hook"), newData); // reinjecting newData in wanted place.
                

                我已成功加載文件并轉換為 base64.然而,我一直未能將結果作為輸出:

                I'am successful to load the file, and to convert to base64. I'am however consistenly failling to get the result as an output :

                var getImageBase64 = function (url) {
                    // 1. Loading file from url:
                    var xhr = new XMLHttpRequest(url);
                    xhr.open('GET', url, true); // url is the url of a PNG image.
                    xhr.responseType = 'arraybuffer';
                    xhr.onload = function(e) { 
                        if (this.status == 200) { // 2. When loaded, do:
                            console.log("1:Response?> " + this.response); // print-check xhr response 
                            var imgBase64 = converterEngine(this.response); // converter
                        }
                    }
                    xhr.send();
                    return xhr.onload(); // <fails> to get imgBase64 value as the function's result.
                }
                
                console.log("4>>> " + getImageBase64('http://fiddle.jshell.net/img/logo.png') ) // THIS SHOULD PRINT THE BASE64 CODE (returned resukt of the function  getImageBase64)
                

                請參閱小提琴.

                See Fiddle here.

                如何使其工作,以便將新數據作為輸出返回?

                解決方案:我的最終實現是在此處可見,然后繼續JS:如何加載位圖圖像并獲取其base64代碼?.

                Solution: my final implementation is visible here, and on JS: how to load a bitmap image and get its base64 code?.

                推薦答案

                JavaScript 中的異步調用(如 xhr)無法像常規函數那樣返回值.編寫異步函數時常用的模式是這樣的:

                Asynchronous calls in JavaScript (like xhr) can't return values like regular functions. The common pattern used when writing asynchronous functions is this:

                function asyncFunc(param1, param2, callback) {
                  var result = doSomething();
                  callback(result);
                }
                
                asyncFunc('foo', 'bar', function(result) {
                  // result is what you want
                });
                

                所以您的翻譯示例如下所示:

                So your example translated looks like this:

                var getImageBase64 = function (url, callback) {
                    var xhr = new XMLHttpRequest(url); 
                    ... // code to load file 
                    ... // code to convert data to base64
                    callback(wanted_result);
                }
                getImageBase64('http://fiddle.jshell.net/img/logo.png', function(newData) {
                  doSomethingWithData($("#hook"), newData);
                });
                

                這篇關于將 XMLhttpRequest 變成函數失敗:異步還是其他?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 部分內容)
                  <tbody id='Ga8IK'></tbody>
              • <i id='Ga8IK'><tr id='Ga8IK'><dt id='Ga8IK'><q id='Ga8IK'><span id='Ga8IK'><b id='Ga8IK'><form id='Ga8IK'><ins id='Ga8IK'></ins><ul id='Ga8IK'></ul><sub id='Ga8IK'></sub></form><legend id='Ga8IK'></legend><bdo id='Ga8IK'><pre id='Ga8IK'><center id='Ga8IK'></center></pre></bdo></b><th id='Ga8IK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Ga8IK'><tfoot id='Ga8IK'></tfoot><dl id='Ga8IK'><fieldset id='Ga8IK'></fieldset></dl></div>

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

                  <legend id='Ga8IK'><style id='Ga8IK'><dir id='Ga8IK'><q id='Ga8IK'></q></dir></style></legend>
                    <bdo id='Ga8IK'></bdo><ul id='Ga8IK'></ul>
                    1. <tfoot id='Ga8IK'></tfoot>

                          主站蜘蛛池模板: 欧美三区视频 | 亚洲黄色av网站 | 女人精96xxx免费网站p | 国产日韩欧美激情 | 一区二区三区四区在线播放 | 国产99精品| 91xh98hx 在线 国产 | 亚洲第一天堂 | 一级片免费视频 | 中文字幕亚洲一区二区三区 | 91色视频在线 | a毛片| 国产精品一区在线 | 全免费a级毛片免费看视频免费下 | 国产在线精品一区二区三区 | 亚洲精品视频免费看 | 日本精品免费 | 亚洲在线中文字幕 | 激情网站 | 久久久国产亚洲精品 | 久久精品91久久久久久再现 | 亚洲综合在线视频 | 久久r久久| 一区二区三区免费 | 自拍偷拍亚洲欧美 | 久久免费精品视频 | 成人免费视频网站在线观看 | 中文字幕成人在线 | www.国产.com| 亚洲天堂精品一区 | 亚洲精品在 | 成人精品毛片国产亚洲av十九禁 | 91免费在线 | 日本精品视频一区二区 | 亚洲精品一区二区另类图片 | 亚洲精选一区二区 | 亚洲国产精品久久久久 | 精品日韩在线观看 | 精品国产乱码久久久 | 一区二区中文字幕 | 天堂久久久久久久 |