日期:2014-05-16  浏览次数:20558 次

struts2+ajax+jquery的Action提交问题
我在Form中定义了一个Action,Form中有一个buttion,点击button后执行一个方法,通过JQuery的Ajax方法提交到另一个Action,然后想根据Action的返回结果,决定是不是执行Form的Action。
但是现在不论Ajax的返回结果是什么Form的Action都被执行。
如果把Form的定义删除之后,Form的Action是可以不执行,但是页面输入的数据又无法提交到表单里,
请问如何解决?
具体的代码如下:
JSP的JS的代码:
function checkSearchAjax()
{
var tmpStr = $("form").serialize();
var urlStr = 'ajaxCustSearchForKenshin.action?' + tmpStr;

$.ajax({
async : false,
cache: false,
type: 'POST',
data: {},
dataType : "json",
url: urlStr,
error: function () {
alert('error');
},
success:callbackFunc
});

}
function callbackFunc(data)
{
alert(data.resultCnt);
 
if(data.resultCnt == "2") {
return false;
  //Form的Action不提交
} else {
  //Form的Action提交
  }
}
JSP的代码:
<s:form name="searchform" id="searchform" action="custSearchForKenshinSer" method="post" theme="simple">
  <s:textfield name="name" maxlength="5" theme="simple" />
  <s:submit type="button" onclick="checkSearchAjax();" value="search" theme="simple" />
</s:form>

------解决方案--------------------
那样子你的表单就一直不能提交的。应该在表单的onsubmit事件的指定函数中返回true或者false
------解决方案--------------------
结贴放分吧