jq ajax progress
1.0.0
輕量級 jQuery 插件,增加了對progress
的支持,並為 $.ajax() 承諾了uploadProgress
npm install jq-ajax-progress
git clone [email protected]:likerRr/jq-ajax-progress.git
在jQuery
腳本之後的 html 中包含src/jq-ajax-progress.min.js
$ . ajax ( url , {
progress : function ( e ) {
// track downloading
} ,
uploadProgress : function ( e ) {
// track uploading
// if (e.lengthComputable) {
// var completedPercentage = Math.round((e.loaded * 100) / e.total);
// console.log(completedPercentage);
//}
}
} )
在某些情況下,當您必須向客戶端發送分塊資料時,最好追蹤剛剛收到的部分。為此,請使用布林選項chunking
(預設為false
)。如果設定為true
,那麼回呼函數中的第二個參數將是一個 chunk 部分。
預設情況下,所有分塊回應都包含已收到的完整文字回應,如果您需要對部分執行某些操作,則應手動剪切它。當您從伺服器向客戶端發送大文本或媒體回應並且您不希望客戶端等待整個回應時,可能的情況之一。
請記住,在幕後,整個回應從頭開始(從零索引)直到最後一部分發生,因此大量資料(理論上)可能會導致效能問題。但是...請記住:)
$ . ajax ( url , {
chunking : true ,
progress : function ( e , part ) {
console . log ( part ) ;
}
} ) ;
安裝節點
運行npm install && npm run build
這將縮小庫並將其放入src
資料夾中