首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

struts2上使用ajax 提交form数据过程

2012-09-10 
struts2下使用ajax 提交form数据过程1.需要引入struts2-dojo-plugin包(struts使用了dojo进行提交)2. 在jsp

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 cssvalue="保存" 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;});});

热点排行