struts2中同一個action被執行兩次

今天在做留言的時候,當刪除留言的時候返回兩個視圖頁面,跟蹤可以看到是同一個action被執行了兩次。
原因:由於我採用的js提交form的,

var test = function(area,form,idsCon,action){
this.area=$(area);
this.form=form;
this.idsCon = idsCon;
this.action = action;
var ids = "";
//var box;
this.box = $(area+" input[type='checkbox']");
this.box.each(function(i){
if($(this).attr("checked"))
if(ids==""||ids==null){
ids = $(this).attr("id");
}else{
ids=ids+","+$(this).attr("id");
}
});
if ($.trim(ids).length==0){
alert("請選擇需刪除的記錄");
return;
}
this.ids = ids;
alert($(form).attr("action"));
var res=confirm("您確定需要刪除嗎?");
if (!res) return;
[color=darkred]// $(form).attr("action",action);[/color] $(idsCon).attr("value",this.ids);
$(form).attr("method","post");
$(form).submit();
}

其中在傳form過來時,我最初考慮一個頁面只有一個form,所示直接傳的<form>,後來才發現頁面中有inclue另外一個頁面也有一個form,這時,submit的時候提交了兩個form,而include頁面中的那個form的action是空的,所以它熱執行當前的action,同時本頁面的action地址沒有改變,也執行同一個action,出現如上所說的情況,
解決方法很簡單,將js中傳遞form的id值,明確區分是哪個form
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章