明天的明天 永远的永远 未知的一切 我与你一起承担 ??

是非成败转头空 青山依旧在 几度夕阳红 。。。
随笔 - 1277, 文章 - 0, 评论 - 214, 阅读 - 320万
  博客园  :: 首页  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

ajax 提交文件

Posted on   且行且思  阅读(55)  评论(0编辑  收藏  举报

html页面:

<form id = "uploadForm" method = "post" enctype = "multipart/form-data">
    <label>选择文件</label>
    <input id = "file" type = "file" name = "file">
    <button id = "upload" type = "button" name = "button">提交</button>
</form>

js代码:

复制代码
function upload(){
    var formData = new FormData;
    var file = document.getElementById("file").files[0];
    formData.append("file",file);
    $.ajax({
        type: 'post',
        url: getRootPath() + '/xxxx/xxxxx',
        data: formData,
        dataType: "json",
        cache: false,
        processData: false,
        contentType: false,
        success: function(data){
            var result = data.returnCode;
            var msg = data.returnMessage;
            if(result === "00"){
            toastr.success("")
            }
            else{
                toastr.waring(msg);
            }
        }
})
}
复制代码

 

后端代码:

@RequestMapping(value="/xxxx",method=RequestMethod.POST,produces = MediaTYpe.XXX)
@ResponseBody
public void a(@RequestParam("file") Multipartile file){
    
}

 

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
历史上的今天:
2014-12-18 MyXls: 导出Excel的各种设置
2008-12-18 xp访问权限问题的解决(绝对有效)
点击右上角即可分享
微信分享提示