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

struts2下使用ajax 提交form数据过程
1.  需要引入struts2-dojo-plugin包(struts使用了dojo进行提交)
2. 在jsp中要添加标签引用:<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
3. 在head部分要添加<sx:head/>引入dojo需要的js
4. form写成<s:form>
5. 提交按钮
<sx:submit cssClass="button" value="保存" notifyTopics="showResult" beforeNotifyTopics="validateForm"/>

6. 可以定义一些提交前后的事件,js可以类似写:
dojo.addOnLoad(function() {
	dojo.event.topic.subscribe('showResult', this, function(data, type, e) {
		if (type == 'load') {
			//请求成功后执行
		} else if (type == 'error') {
			//请求失败后执行
		}
	});
	dojo.event.topic.subscribe('validateForm', this, function(event, widget) {
		
		//发送请求前执行
		//若想阻止提交,使用 event.cancel = true;
	});
});