日期:2014-05-18  浏览次数:20652 次

用ajax提交一个到action的表单,跳转到页面后没有新增数据
本帖最后由 xzs7190966 于 2013-09-02 15:29:28 编辑
js代码
function checeAddInvoice(id) {
var contract_id = id;
var money=document.getElementById("invoice_money").value;

$.ajax({
type : "POST",
url : "${pageContext.request.contextPath}/checkAddInvoice.action",
data : "contract_id=" + contract_id+"&money="+money,
async : false,
success : function(data) {
if (data == "true") {
layer.msg('正在添加,请稍后...');
document.getElementById("form2").submit();  //提交form2表单后,跳转后的页面并没有立即显示刚刚新增的发票数据
} else {
$.layer({
shade : [ 0.5, '#000', true ],
area : [ 'auto', 'auto' ],
dialog : {
msg : '添加金额已超过合同金额,是否添加并更新合同总额?',
btns : 2,
type : 4,
btn : [ '更新', '不更新', ],
yes : function() {
layer.msg('您选择了继续添加', 2, 1);
},
no : function() {
layer.msg('取消了', 2, 4);
}
}
});

}
}
});

};




jsp代码
<form id="form2" method="post" action="insertInvoice.action">
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="hidden" name="invoice.contract_id"
value="${contract1.contract_id}"> <input type="hidden"
name="invoice.customer_id" value="${contract1.customer_id}">
<input type="hidden" name="type" value="2">
&nbsp&nbsp发票号码: <input type="text" size="40"
name="invoice.invoice_number"> &nbsp&nbsp开票时间: <input
name="invoice.invoice_time" type="text" class="Wdate"
onClick="WdatePicker({dateFmt:'yyyy-MM-dd'})">
&nbsp&nbsp开票金额: <input id="invoice_money" type="text" size="20"
name="invoice.invoice_money"> &nbsp<input type="button"
onclick="checeAddInvoice('${contract1.contract_id}')"
value="添加发票" />
</td>
</tr>
</table>
</form>


添加完成后,action跳转到该页面,列表中并没有立即显示刚刚添加的数据