aspshipin 2013-10-06
情况是这样的:
Action:
public class HomeMemberAction extends ParentAction{
private HomeMember homeMember;
//查询方法
public String homeMemberList(){
System.out.println("===" + homeMember.getMemberName());
homeMemberList = this.homeMemberService.getHomeMemberList();
return Action.SUCCESS;
}
public HomeMember getHomeMember() {
return homeMember;
}
public void setHomeMember(HomeMember homeMember) {
this.homeMember = homeMember;
}
}
配置文件:
<action name="homeMemberList" class="com.issweb.homemember.web.HomeMemberAction" method="homeMemberList">
<result type="json">
<!-- 不序列化Action里为null的字段 -->
<param name="excludeNullProperties">true</param>
<param name="root">homeMemberList</param>
</result>
</action>
js:
function loadHomeMemberData(){
//组装参数
var memberName = $("#memberName").val();
var sex = $("#sex").val();
var age = $("#age").val();
var nickName = $("#nickName").val();
//请求后台
$.ajax({
url:"/member/homeMemberList.action",
type:"post",
dataType:"json",
data:{
"homeMember.memberName":memberName,
"homeMember.sex":sex,
"homeMember.age":age,
"homeMember.nickName":nickName
},
beforeSend:function(){
$('#loading').show();//请求之前,展显进度条
},
complete:function(){
$('#loading').hide();//请求之后,隐藏进度条
},
success:createTable
});
}
描述:
ajax提交数据到Action中,如果想让提交的数据自动封装到homeMember 类中,需要在提交的时候,做以下手脚:
data:{
"homeMember.memberName":memberName,
"homeMember.sex":sex,
"homeMember.age":age,
"homeMember.nickName":nickName
},
以Action对象中的属性名字做为前缀。
千万要注意:js中获得参数值方式一定要正确,不然后台获取不到参数,例如:var memberName = $("#memberName").val();
如果写成:var memberName = $("memberName").val(); 前台也不会报错,后台也获取不到值,很不好确定是哪里的原因。
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
本文实例讲述了php+ ajax 实现的写入数据库操作。分享给大家供大家参考,具体如下:。<input class="tel" type="text" placeholder="请输入您的手机号码&q