标签:style blog class code java tar javascript color get string set
jsp
$(‘#userId‘).change(function() { $.ajax({ url: "${ctx}/test/checkUser.do", contentType: "application/json;charset=utf-8", type: "get", data:{ userId:$("#userId").val() }, success: function(data) { if(data!=‘‘){ alert(data); } }, error: function() { alert("系统发生异常,请稍候再试!\n\n有任何疑问,请联系系统管理员!"); } }); });
controller
/** * 检查用户名重复 * @param response * @param userId * @return */ @RequestMapping( value = "/test/checkUser", method = RequestMethod.GET ) @ResponseBody public String checkUser( HttpServletResponse response,String userId ) { Users users = usersService.findOne(userId); String errorMessage = ""; if(users!=null){ // 显示errorMessage errorMessage = "输入的ID已重复!"
} return errorMessage; }
jsp内data即返回的string,如果要返回list,需要引用json的包
import
net.sf.json.JSONObject;
JSONObject jsonObject = new JSONObject(); jsonObject.put("data",stars);
另外jsp中可以通过这种方式来获取json返回的值
$.getJSON("url",回调函数);
spring ajax提交并返回数据方式,码迷,mamicode.com
标签:style blog class code java tar javascript color get string set
原文地址:http://www.cnblogs.com/singerGodZhu/p/3700854.html