js代码
function addRole()
{
var roleName='哈哈哈';
var roleDescr='哈哈哈';
var msg="";
if(null==roleName || ""==roleName){
msg+="角色名称不能为空<br>";
}
if(null==roleDescr || ""==roleDescr){
msg+="角色描述不能为空<br>";
}
if(null!=msg && ""!=msg){
$.ligerDialog.alert(msg, '提示', 'warn');
return false;
}
$.ajax({
type:"POST",
url:"<%=basePath%>company/saveRoleInfo.do?roleName="+encodeURI(encodeURI(roleName))+"&roleDescr="+roleDescr,
data:{name:1},
dataType:'text',
contentType:"application/x-www-form-urlencoded:charset=UTF-8",
success:function(data){
if("true"==data){
parent.f_closeTab('company_role_add');
}else{
$.ligerDialog.alert("角色添加失败,请稍后再试!", '提示', 'error');
}
}
});
}
后台代码:
@RequestMapping("company/saveRoleInfo.do")
public String saveRoleInfo(String roleName,String roleDescr,HttpServletRequest request,HttpServletResponse response){
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
System.out.println( URLDecoder.decode(roleName,"UTF-8")+"\n"+roleDescr+"\n"+request.getParameter("name"));
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//boolean flag=this.companyRoleService.saveRoleInfo(roleName, roleDescr);
try {
response.getWriter().write(Boolean.toString(true));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
输出结果中name总是null
js中的data:{name:1}以及data:"name="+1这两种方式都试过,均为null 求帮助
------解决方案--------------------
试试 $.get("http://www.baoidu.com?a=",function(data){});这个能获取吗?我一直用这个的 都没问题
------解决方案--------------------
contentType 貌似java用不上,可去掉
data:{'name':1} //变量名用引号括起来
另,ie10可打开开发者工具查看页面相关错误