Jquery Ajax Upload File (html5 FormData)

How to use Jquery Ajax to upload files with uploading progress


get single file

let data = $('input[tpye=file]')[0].files[0]
let file = new FormData()
file.append('file',data)

pakage uploading progress xhr function

function onprogress(){
    var loaded = evt.loaded;
    var tot = evt.total;
    var per = Math.floor(100*loaded/tot)
    console.log(per)
}

function xhr(){
    let xhr = $.ajaxSettings.xhr()
    if(onprogress && xhr.upload){
        xhr.upload.addEventListener("progress" , onprogress, false);
        return xhr;
    }
}

use $.ajax() to upload

$.ajax({
    url:'url address',
    type:'POST',
    contentType:false,
    processData:false,
    data:file,
    xhr:xhr,
    success:function(res){
        //handle funciton
    }
})

more about jquery ajax

本文链接:Jquery Ajax Upload File (html5 FormData)

转载声明:本站文章若无特别说明,皆为原创,转载请注明来源:PorYoung,谢谢!^^

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇