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

  • <small id='4JVa3'></small><noframes id='4JVa3'>

    <tfoot id='4JVa3'></tfoot>

      <bdo id='4JVa3'></bdo><ul id='4JVa3'></ul>

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

        顯示使用 XHR2/AJAX 下載文件的進度條

        Show a progress bar for downloading files using XHR2/AJAX(顯示使用 XHR2/AJAX 下載文件的進度條)
          <bdo id='8rVTD'></bdo><ul id='8rVTD'></ul>
          <legend id='8rVTD'><style id='8rVTD'><dir id='8rVTD'><q id='8rVTD'></q></dir></style></legend>
          <i id='8rVTD'><tr id='8rVTD'><dt id='8rVTD'><q id='8rVTD'><span id='8rVTD'><b id='8rVTD'><form id='8rVTD'><ins id='8rVTD'></ins><ul id='8rVTD'></ul><sub id='8rVTD'></sub></form><legend id='8rVTD'></legend><bdo id='8rVTD'><pre id='8rVTD'><center id='8rVTD'></center></pre></bdo></b><th id='8rVTD'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8rVTD'><tfoot id='8rVTD'></tfoot><dl id='8rVTD'><fieldset id='8rVTD'></fieldset></dl></div>

                <tfoot id='8rVTD'></tfoot>

                  <tbody id='8rVTD'></tbody>
              1. <small id='8rVTD'></small><noframes id='8rVTD'>

                  本文介紹了顯示使用 XHR2/AJAX 下載文件的進度條的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用 Ajax 下載文件并顯示自定義下載進度條.

                  問題是我不明白該怎么做.我編寫了代碼來記錄進度,但不知道如何啟動下載.

                  注意:文件屬于不同類型.

                  提前致謝.

                  JS

                  //文件下載filelist.on('click', '.download_link', function(e){e.preventDefault();var id = $(this).data('id');$(this).parent().addClass("download_start");$.ajax({xhr: 函數 () {var xhr = 新窗口.XMLHttpRequest();//處理下載進度xhr.addEventListener("進度", function (evt) {如果(evt.lengthComputable){var percentComplete = evt.loaded/evt.total;console.log(percentComplete);}}, 錯誤的);返回xhr;},完成:函數(){console.log("請求完成");}})});

                  HTML 和 PHP

                   <li><div class="f_icon"><img src="'.$ico_path.'"></div><div class="left_wing"><div class="progressbar"></div><a class="download_link" href="#" id="'.$file_id.'"><div class="f_name">'.$full_file_name .'</div></a><div class="f_time_size">'.日期(M d,Y",$file_upload_time).'  '.human_filesize($file_size) .'</div></div><div class="right_wing"><div ="f_delete"><a class="btn btn-danger" href="#" aria-label="Delete" data-id="'.$file_id.'" data-filename="'.$full_file_name.'"><;i class="fa fa-trash-o fa-lg" aria-hidden="true" title="除這?"></i></a></div></div></li>

                  解決方案

                  如果您想向用戶顯示下載過程的進度條 - 您必須在 xmlhttprequest 中進行下載.這里的問題之一是,如果您的文件很大 - 它們將在瀏覽器將它們寫入磁盤之前保存在瀏覽器的內存中(使用常規下載文件時直接保存到磁盤,這樣可以在大文件上節省大量內存).

                  另一個需要注意的重要事項 - 為了使 lengthComputable 為真 - 您的服務器必須發送帶有文件大小的 Content-Length 標頭.

                  這里是javascript代碼:

                  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div id="a1" data-filename="filename.xml">點擊下載</div><腳本>$('#a1').click(function() {var that = this;var page_url = 'download.php';var req = new XMLHttpRequest();req.open("POST", page_url, true);req.addEventListener("進度", function (evt) {如果(evt.lengthComputable){var percentComplete = evt.loaded/evt.total;console.log(percentComplete);}}, 錯誤的);req.responseType = "blob";req.onreadystatechange = function () {如果(req.readyState === 4 && req.status === 200){var filename = $(that).data('filename');if (typeof window.chrome !== 'undefined') {//鉻版本var link = document.createElement('a');link.href = window.URL.createObjectURL(req.response);link.download = 文件名;鏈接.click();} else if (typeof window.navigator.msSaveBlob !== 'undefined') {//IE版本var blob = new Blob([req.response], { type: 'application/force-download' });window.navigator.msSaveBlob(blob, 文件名);} 別的 {//火狐版本var file = new File([req.response], filename, { type: 'application/force-download' });window.open(URL.createObjectURL(file));}}};req.send();});</腳本>

                  下面是你可以使用的 php 代碼示例:

                  <塊引用>

                  請注意,我添加了一個睡眠來模擬慢速連接以在 localhost 上進行測試.您應該在生產中刪除此 :)

                  I am trying to download files using Ajax and show a custom download progress bar.

                  The problem is I can't understand how to do so. I wrote the code to log the progress but don't know how to initiate the download. NOTE: The files are of different types. Thanks in advance. JS// Downloading of files filelist.on('click', '.download_link', function(e){ e.preventDefault(); var id = $(this).data('id'); $(this).parent().addClass("download_start"); $.ajax({ xhr: function () { var xhr = new window.XMLHttpRequest(); // Handle Download Progress xhr.addEventListener("progress", function (evt) { if(evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; console.log(percentComplete); } }, false); return xhr; }, complete: function () { console.log("Request finished"); } }) }); HTML and PHP <li> <div class="f_icon"><img src="' . $ico_path . '"></div> <div class="left_wing"> <div class="progressbar"></div> <a class="download_link" href="#" id="'.$file_id.'"><div class="f_name">' . $full_file_name . '</div></a> <div class="f_time_size">' . date("M d, Y", $file_upload_time) . '&nbsp; &#149; &nbsp;' . human_filesize($file_size) . '</div> </div> <div class="right_wing"> <div class="f_delete"> <a class="btn btn-danger" href="#" aria-label="Delete" data-id="'.$file_id.'" data-filename="'.$full_file_name.'"><i class="fa fa-trash-o fa-lg" aria-hidden="true" title="Delete this?"></i> </a> </div> </div> </li> 解決方案 If you want to show the user a progress-bar of the downloading process - you must do the download within the xmlhttprequest. One of the problems here is that if your files are big - they will be saved in the memory of the browser before the browser will write them to the disk (when using the regular download files are being saved directly to the disk, which saves a lot of memory on big files). Another important thing to note - in order for the lengthComputable to be true - your server must send the Content-Length header with the size of the file. Here is the javascript code: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="a1" data-filename="filename.xml">Click to download</div> <script> $('#a1').click(function() { var that = this; var page_url = 'download.php'; var req = new XMLHttpRequest(); req.open("POST", page_url, true); req.addEventListener("progress", function (evt) { if(evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; console.log(percentComplete); } }, false); req.responseType = "blob"; req.onreadystatechange = function () { if (req.readyState === 4 && req.status === 200) { var filename = $(that).data('filename'); if (typeof window.chrome !== 'undefined') { // Chrome version var link = document.createElement('a'); link.href = window.URL.createObjectURL(req.response); link.download = filename; link.click(); } else if (typeof window.navigator.msSaveBlob !== 'undefined') { // IE version var blob = new Blob([req.response], { type: 'application/force-download' }); window.navigator.msSaveBlob(blob, filename); } else { // Firefox version var file = new File([req.response], filename, { type: 'application/force-download' }); window.open(URL.createObjectURL(file)); } } }; req.send(); }); </script> And here is an example for the php code you can use:<?php $filename = "some-big-file"; $filesize = filesize($filename); header("Content-Transfer-Encoding: Binary"); header("Content-Length:". $filesize); header("Content-Disposition: attachment"); $handle = fopen($filename, "rb"); if (FALSE === $handle) { exit("Failed to open stream to URL"); } while (!feof($handle)) { echo fread($handle, 1024*1024*10); sleep(3); } fclose($handle); Note that I added a sleep to simulate a slow connection for testing on localhost. You should remove this on production :) 這篇關于顯示使用 XHR2/AJAX 下載文件的進度條的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網! 【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
                  上一篇:如何在沒有 jQuery 的情況下在 JavaScript 中打開 J 下一篇:XMLHttpRequest 模塊未定義/未找到
                  相關文檔推薦 即使在調用 abort (jQuery) 之后,瀏覽器也會等待 Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成) JavaScript innerHTML 不適用于 IE? JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?) XMLHttpRequest 無法加載,請求的資源上不存在“A XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分 XHR HEAD 請求是否有可能不遵循重定向 (301 302) Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302)) NETWORK_ERROR:XMLHttpRequest 異常 101 NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101) XMLHttpRequest 206 部分內容 XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)
                  <legend id='oFHtX'><style id='oFHtX'><dir id='oFHtX'><q id='oFHtX'></q></dir></style></legend><tbody id='oFHtX'></tbody><bdo id='oFHtX'></bdo><ul id='oFHtX'></ul><strong id='oFHtX'><tr id='oFHtX'></tr></strong><label id='oFHtX'></label><strike id='oFHtX'></strike><option id='oFHtX'><u id='oFHtX'><ol id='oFHtX'><blockquote id='oFHtX'></blockquote></ol></u></option><table id='oFHtX'></table><small id='oFHtX'><b id='oFHtX'></b><style id='oFHtX'></style><i id='oFHtX'></i><small id='oFHtX'><dl id='oFHtX'></dl><fieldset id='oFHtX'><form id='oFHtX'><dt id='oFHtX'><code id='oFHtX'></code><code id='oFHtX'><div class="qwawimqqmiuu" id='oFHtX'></div></code></dt></form></fieldset></small></small><thead id='oFHtX'><kbd id='oFHtX'></kbd><sup id='oFHtX'><th id='oFHtX'></th></sup></thead><sup id='oFHtX'><strong id='oFHtX'><i id='oFHtX'></i></strong><small id='oFHtX'><div class="qwawimqqmiuu" id='oFHtX'></div></small><ins id='oFHtX'></ins></sup><legend id='oFHtX'><table id='oFHtX'></table></legend><q id='oFHtX'></q><small id='oFHtX'></small><noframes id='oFHtX'><i id='oFHtX'><tr id='oFHtX'><dt id='oFHtX'><q id='oFHtX'><span id='oFHtX'><b id='oFHtX'><form id='oFHtX'><ins id='oFHtX'></ins><ul id='oFHtX'></ul><sub id='oFHtX'></sub></form><legend id='oFHtX'></legend><bdo id='oFHtX'><pre id='oFHtX'><center id='oFHtX'></center></pre></bdo></b><th id='oFHtX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='oFHtX'><tfoot id='oFHtX'></tfoot><dl id='oFHtX'><fieldset id='oFHtX'></fieldset></dl></div><tfoot id='oFHtX'></tfoot> 欄目導航 前端問題解決Java問題php問題Python問題C#/.NET問題C/C++問題移動開發問題數據庫問題 最新文章 • node.js安裝依賴包 yarn install... • layui表格中選擇下拉框同時如... • vue中yarn install報錯:info The... • js報錯:Uncaught SyntaxError: Un... • layui時間格式錯誤或者出現... • 在javascript中將GBK轉UTF-8的實例... • AJAX在GBK編碼頁面中傳中文參... • 使用純 JavaScript 將電話號碼格... • 圖片上的傳單自定義坐標... • 用于在 JavaScript 中格式化數字... • 在 Leaflet 中獲取當前地圖范圍... • 增量 gulp 少構建... 熱門文章 • node.js安裝依賴包 yarn install... • layui表格中選擇下拉框同時如... • vue中yarn install報錯:info The... • js報錯:Uncaught SyntaxError: Un... • layui時間格式錯誤或者出現... • 在javascript中將GBK轉UTF-8的實例... • AJAX在GBK編碼頁面中傳中文參... • 使用純 JavaScript 將電話號碼格... • 圖片上的傳單自定義坐標... • 用于在 JavaScript 中格式化數字... • 在 Leaflet 中獲取當前地圖范圍... • 增量 gulp 少構建... 熱門標簽 旅游公司 服裝服飾 機械設備 電子產品 政府協會 網絡營銷 環保科技 科技公司 家政服務 營銷型 環保 軟件開發 傳媒公司 金融服務 雙語 培訓機構 零部件 教育培訓 博客主題 軸承 新聞資訊 視頻 進銷存系統 bootstrap 商城模板 商務合作 廣告設計 驗證碼 門戶 ar OElove 漫畫網 全景 商城 區塊鏈 虛擬幣 你畫我猜 卡券 動畫特效 在線客服 地板 域名停放 canvas html5 svg 博客 攝影 導航 小說源碼 ai智能 蘋果cms 微擎微贊 微商 訂單系統 小程序 電影源碼 微信程序 帝國cms 掃碼點餐 jquery angular 視頻打賞 thinkphp 360 動畫模板 淘寶客 音樂 分發系統 o2o 微擎
                  網站首頁 - 聯系我們- 免責聲明- 網站公告 - 標簽分類- 網站地圖 Copyright © 2022-2023 HTML5模板網 版權所有并保留所有權 粵ICP備14083021號 感谢您访问我们的网站,您可能还对以下资源感兴趣: 久久久久久久av|日韩在线中文|看一级毛片视频|日本精品二区|成人深夜福利视频|武道仙尊动漫在线观看 主站蜘蛛池模板: 黄色av网站在线观看 | 亚洲vs天堂| 仙人掌旅馆在线观看 | 欧美v免费 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 亚洲一区二区日韩 | 亚洲免费网 | 精品一区二区三区av | 日韩国产一区二区 | 国产视频在线一区二区 | 九九综合 | 国产日韩中文字幕 | 夜夜爽99久久国产综合精品女不卡 | 欧美狠狠操 | 色999视频 | 久久久精品视频一区二区三区 | 亚洲精品电影网在线观看 | 日本不卡视频在线播放 | 欧美国产激情 | 一区二区三区视频在线观看 | 日韩成人av在线 | 不卡一区 | 久久av一区 | 欧美一区二区三区免费电影 | 国产网站在线播放 | 久久夜色精品国产 | 国产视频一区在线 | 伊人网站在线观看 | 天天夜干 | 福利片在线看 | 国产精品一区二区三区四区五区 | 欧美特级黄色 | 人人做人人澡人人爽欧美 | 日韩高清一区 | 在线观看国产wwwa级羞羞视频 | 一区二区免费在线观看 | 久久大香 | 日韩二三区 | 成人视屏在线观看 | 在线观看视频福利 | 成人国产精品色哟哟 | (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); <object id="aqgyy"></object><object id="aqgyy"><ul id="aqgyy"></ul></object><li id="aqgyy"></li>