1. 程式人生 > >Ajax登入校驗

Ajax登入校驗


		@RequestMapping("/checkGoodsName")
		public @ResponseBody() Msg checkGoodsName(@RequestBody() Goods goods){
			Boolean result = service.checkGoodsName(goods.getGoods_name());
		System.out.println(result);
			if(result){
				return new Msg("商品名稱可用");
			}else{
				return new Msg("商品名稱已存在");
				
			}
		}

controller.java

	function checkGoodsName(gname) {
			var div=$("#checkName");
			//alert(gname)
			if(gname!=""){
				$.ajax({
					type:"post",
					url:"${pageContext.request.contextPath }/goods/checkGoodsName.action",
					data:'{"goods_name":"'+gname+'"}',
					contentType:"application/json;charset=utf-8",
					success:function(data){
						
						if(data.msg=="商品名稱可用"){
							div.html("<font color='black'>商品名稱可用</font>")
						}else{
							div.html("<font color='black'>商品名稱已存在</font>")
					}
					}
					
				})
				
			}else{
				div.html("")
				
			}