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

jquery 的$.post()参数如何穿给url中调用的方法作为参数

2013-08-01 
jquery 的$.post()参数怎么穿给url中调用的方法作为参数js代码var pwdArray [] $(.yellow_btn input)

jquery 的$.post()参数怎么穿给url中调用的方法作为参数
js代码


var pwdArray = []; 
$(".yellow_btn input").click(function(){
            $("input[type=password]").each(function(){
            pwdArray.push($(this).val());
            });
            var oldPwd = pwdArray[0];
            var newPwd = pwdArray[1];
$.post( $.frontPath + "updatePassword.json",{newPassword:newPwd,oldPassword:oldPwd},function(data){
$.refresh($.frontPath + "personal/safeOk"); 
});
});


调用的方法代码

@RequestMapping(value="updatePassword.json")
public Map<String, Object> updatePasswprd(ModelMap map , String newPassword , String oldPassword ){
long userId = this.getFrontUserId();
if(userId == Global.NULL_ID)
return this.createJSONError("no login");
boolean isMatch = false;
boolean isUpdate = false;
if( oldPassword != null && oldPassword.length() > 0 ){
isMatch = this.userService.checkPassword(oldPassword, userId);
if( isMatch && newPassword != null && newPassword.length() > 0 ){ 
isUpdate = this.userService.updateUserPassword(newPassword, this.userService.getUser(userId));
}
}
map.put("isMatch", isMatch);
map.put("isUpdate", isUpdate);
map.put("messageUpdate", isUpdate?"更新成功":"更新失败");
map.put("messageMatch", isMatch?"密码正确":"密码不正确");
return map;
}


我想让$.post()方法中的两个参数,传入public Map<String, Object> updatePasswprd(ModelMap map , String newPassword , String oldPassword ){这个方法中,作为参数newPassword,和oldPassword的值 jQuery URL String 函数 地图


[解决办法]
http://www.cnblogs.com/tim190/archive/2010/10/20/1856523.html
[解决办法]
本帖最后由 showbo 于 2013-07-06 22:35:59 编辑 一般传递的是键值对字符串对象,然后服务器用request对象获取数据后再调用对应的方法传递这些参数进去

如果是webservice,可能需要JSON格式的字符串,这样可以用json2.js序列化json对象为对应的json字符串后再传递,不要指定键名称。

热点排行
Bad Request.