spring mvc 下ajax form 如何上传附件?
目前无奈只能分2步做了。
[code="js"]
function addOrUpdate(){
var r = $('#projectForm').form('validate');
if(!r) {
return false;
}
$.post("proj/addOrUpdate",$("#projectForm").serializeArray(),function(data){
if(data.result != false){
$.messager.confirm('提示', '是否要上传附件?',function(result){
//执行待操作步骤
if (result) {
$("#projectForm").hide();
$("#uploadPannel").show();
$("#pId").val(data.pid);
}else{
$('#MyPopWindow').window('close');
$('#projectTable').datagrid('reload');
$.messager.alert('提示',data.mes,'info');
}
});
}else{
$.messager.alert('提示',data.mes,'info');
}
});
}
[/code]
[code="html"]
<!-- 验证还是jquery-validation好用,这里省事没用 -->
<form id="projectForm" method="post"
style="margin: 10; text-align: center;">
<input type="hidden" name="id" id="uuid">
<table class="popTable">
<tr>
<td class="alignR">项目名称:</td>
<td>
<input name="name" style="width: 200" validType="length[1,32]"
class="easyui-validatebox" required="true" />
</td>
</tr>
<tr>
<td class="alignR">项目类别:</td>
<td>
<input id="projTypeList" name="type.id" style="width:200"/>
</td>
</tr>
<tr>
<td class="alignR">项目需求方:</td>
<td>
<input id="projDemanderList" name="demander.id" style="width:200"/>
</td>
</tr>
<tr>
<td class="alignR">终端厂商:</td>
<td>
<input id="mftList" name="mft_id" style="width:200"/>
</td>
</tr>
<tr>
<td class="alignR">项目状态:</td>
<td>
<input id="statusList" name="status.id" style="width:200"/>
</td>
</tr>
<tr>
<td class="alignR">责任人:</td>
<td>
<input id="dutierList" name="duty_id" style="width:200"/>
</td>
</tr>
<tr>
<td width="30%" class="alignR">计划完成时间:</td>
<td>
<input name="planEndTime" style="width: 200" class="Wdate"
onClick="WdatePicker()">
</td>
</tr>
<tr>
<td class="alignR">备注:</td>
<td>
<textarea name="note" style="width: 200"
class="easyui-validatebox"
rows="10" cols="1"></textarea>
</td>
</tr>
<tr>
<td colspan="2" class="alignC">
<a href="#" id="btn-back" onclick="closeWindow();"
class="easyui-linkbutton" iconCls="icon-back">返回</a>
<a href="#" id="btn-add" onclick="addOrUpdate();"
class="easyui-linkbutton" iconCls="icon-save">保存</a>
<br/>
<br/>
<br/>
*请选择IE6以上或者firefox浏览器上传附件。
</td>
</tr>
</table>
</form>
[/code]