jquery ajax传递参数怎么获取
1个回答
展开全部
$.ajax({
url: '../api/findUser',
type: "POST",
data: {//data就是参数,是json格式
userCode: '201702009',
userName: '张三'
},
async: false,
dataType: 'json',
cache: false,
success: function (args) {
//请求成功返回后执行的动作
},
error: function (args) {
//请求失败后执行的动作
}
});
//然后服务端获取参数值:
//如果是:SpringMVC框架:(框架自动填装参数值)
@RequestMapping(value = "/findUser", method = RequestMethod.POST)
public User findUser(@RequestParam(value = "userCode") String userCode,
@RequestParam(value = "userName") String userName){
//.......
}
//如果是Servlet:
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userCode= request.getParameter("userCode");
String userName= request.getParameter("userName");
//.......
}
希望能帮到你!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询