jQuery ajax 文件上传

原创
2014/10/11 12:01
阅读数 734

html

<!-- lang: html -->
<form id="upload" method="post" action="/bucket/${buck.name}/up" enctype="multipart/form-data" >
 <input type="hidden" name="prefix" value="${prefix}"/>
 <input type="file" name="upfile" id="file_upload" class="filestyle"/>
</form>

javascript

<!-- lang: js -->
var dat = new FormData()

dat.append('prefix', $(':input[name=prefix]').val()) dat.append('file', $(':input[name=upfile]')[0].files[0]) var req = $.ajax({ url: $('#upload').attr('action'), data: dat, dataType: 'json', type: 'POST', contentType: false, processData: false })

req.done(function(msg) { alert(msg) })

展开阅读全文
加载中

作者的其它热门文章

打赏
0
18 收藏
分享
打赏
2 评论
18 收藏
0
分享
返回顶部
顶部