【问题标题】:how to send ajax call of file upload to controller in spring MVC如何在spring MVC中将文件上传的ajax调用发送到控制器
【发布时间】:2014-12-08 15:22:21
【问题描述】:

您好,我有一个对话框,我正在上传文件。在单击上传按钮时,我正在调用一个 java 脚本,我想在其中编写一个 ajax 调用以将请求发送到控制器。以及将文件保存到本地机器并返回成功字符串的控制器代码应该是什么。请让我知道是否有人使用 ajax 调用做到了这一点。就好像我没有使用 ajax 调用一样,我可以上传文件并将其保存到本地。 提前致谢。

 I want to submit a file but not through form action submit but ajax call something like this var formdata=document.getElementById("Uploadfile"); 
var fd = new FormData(formdata);
fd.append("CustomField","This is an additional data");
$.ajax({
    type: "POST",
    url: contextPath+"/fileUploadForm",
    data: fd,
    enctype:"multipart/form-data",
    processData: false,
    contentType: false, 

    success: function(data){
            alert("inside success ***");
    } ,
    error: function(){
        alert("error has occured");

        }
});

还有什么是控制器代码??

【问题讨论】:

    标签: javascript jquery ajax spring-mvc


    【解决方案1】:

    就个人而言,我从未能够执行 ajax 调用来更新文件。特别是在较旧的 IE 版本中。我使用这个插件来执行表单的 ajaxsubmit,其中包含文件。易于使用。

    http://jquery.malsup.com/form/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 2016-01-20
      • 2013-07-03
      • 1970-01-01
      • 2012-09-09
      • 2016-12-06
      • 2016-12-10
      相关资源
      最近更新 更多