ajax 假上传文件

 

1.

<form name="certForm" id="certForm" method="post" action="xxx.htm" enctype="multipart/form-data" target="uploadCertIframe">
<table>
<tr>
<td class="ft-right" width="10%"><font color="red">* </font>选择你要上传的证书文件</td>
<td width="15%">
<input type="file" id="certFile" name="certFile"/>
</td>
<input type="text" class="i-text" size="27" name="password" id="password" value="$!certForm.password"/></td>
</td>
</tr>
</table>

<div class="tb-tfoot tb-tfoot-noborder">
<span class="btn"><input type="submit" value="提交" onclick="return submitCheck()"></span>
</div>
</form>
form.target属性指定表单提交的页面 就是以下的iframe  的名字 ,后端处理结果页面如vm返回到此iframe 中,然后做页面跳转,产生类似异步提交的错觉。

2.

<iframe style="display:none" name="uploadCertIframe" id="uploadCertIframe"></iframe>

 

3.

@RequestMapping(value = "xxx.htm", method = RequestMethod.POST)
public String createxxxByImport(ModelMap modelMap, WebRequest request, xxxForm xxxForm) {


modelMap.addAttribute("xxx", xxxxForm.getxxxAlias());

return "xxx.vm";
}

4.xxx.vm js处理  注:要操作iframe 上面的页面得用parent来操作

<div id = "result">$!result</div>
<script type="text/javascript">
var result = $("#result").text();
if(result == "T"){
window.parent.$(".tip-success").show();
setTimeout(function(){
parent.document.location.href ='/xx/xxManage.htm?xxx='+xxx;
},3000);
}
</script>

 

posted @ 2015-01-22 00:40  隔壁的老郭  阅读(198)  评论(0编辑  收藏  举报