我有一个 ajax 调用:发生的情况是我单击了一个图像,该图像单击了我不希望显示的“输入文件”。当输入 val() 更改时uploadListener()
,调用方法,这基本上是一个将文件获取到服务器的 ajax 方法“将其上传到服务器”代码如下所示:html:
<img id="${assayAssessRequest.id}" src="[@spring.url '/images/buttons/upload.jpg'/]" onclick="uploadFile(this);" title="Upload File" />
<form id="uploadForm" action="[@spring.url '/assay/designability/uploadFile.htm'/]" method="POST" enctype="multipart/form-data">
<div style="display: none;">
[@spring.formInput path="multiPartBean.file" fieldType="file" attributes="title='path' class='upload' accept='.txt,.csv,.zip'" /]
[@spring.formHiddenInput path="multiPartBean.fileName" attributes=" onchange='uploadListener();'class='uploadFileName'" /]
[@spring.bind "multiPartBean"/]
</div>
<input type="submit" id="uploadButton" value="upload" />
</form>
脚本:
function uploadFile(){
document.getElementById('inputFile').click();
}
function uploadListener(){
$('#uploadForm').attr("action","[@spring.url '/assay/designability/uploadFile.htm'/]");
alert($('#uploadForm').attr('action'));
this.document.getElementById("uploadForm").submit = true;
alert("After Submit");
return false;
}
服务器控制器:
@Controller
@PreAuthorize("isAuthenticated()")
@RequestMapping("/assay/designability")
@SessionAttributes({"assayAssessmentsInitializersBean","assayAssessmentsRequestsDetailsBean"})
public class AssayDesignabilityController extends AssayBaseController {
@RequestMapping(value = "/uploadFile",method= RequestMethod.GET)
public String uploadFile(@RequestParam(value = "file")Object file){
MultipartFile multipartFile=(MultipartFile)file;
logger.info(multipartFile.getName());
return multipartFile.getName();
}
}
现在当我做所有这些时,响应让我胡说八道,当我尝试调试时,我从来没有进入控制器方法。有什么帮助吗??
编辑: 现在我尝试提交它我已经更新了代码并且我有相同的行为没有响应。