1

我有这个简单的形式:

<form id="myForm" method="POST" action="/project/upload" target="myFrame"
enctype="multipart/form-data">


Please select a file to upload : <input id="file" type="file" name="file" />
<input type="button" onclick="initSubmit()" value="upload" />
</form>             
<iframe name="myFrame" height=0 width=0></iframe>

我收到以下错误:

org.springframework.web.multipart.MultipartException: The current request is not a multipart request

这是我的javascript:

function submitForm() {
    $("form#myForm").submit();
}

function initSubmit() {

$('form#myForm').submit(function () {
    $.post('/project/upload', $('form#myForm').serialize(), function (data, textStatus) {
            debugger;
         alert("Yeah!, i can get the call back!");
    });
    return false;
});
submitForm();

}

这是我的控制器方法:

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String handleFormUpload( 
    @RequestParam("file") MultipartFile file,HttpServletResponse response ) throws IOException{
if (!file.isEmpty()) {
 // handle here
 }
return imageURL;
}

我 100% 确定 ajax 调用对我的控制器无效

ps 我这样做是为了回调函数。我需要在客户端接收图像URL,显然表单回调很复杂。

ps #2 - 在不添加 js 的情况下定期提交表单,可以,但是我无法获取回调上下文

4

0 回答 0