ajax同步查询

前端之家收集整理的这篇文章主要介绍了ajax同步查询前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.jsp代码

<dl>
			<label>注册手机号</label>
				<input type="text" name="phoneNo" id="phoneNo" onkeyup="trigger()" class="" maxlength="20"/>
		</dl>
	 	<dl>
			<label>用户编号</label>
				<input type="text" name="userId" id="userId" class="" maxlength="20"/>
		</dl>
	 	<dl>
			<label>姓名</label>
				<input type="text" name="xm" id="xm" class="" maxlength="20"/>
		</dl>
	 	<dl>
			<label>身份证号</label>
				<input type="text" name="idno" id="idno" class="" maxlength="20"/>
		</dl>

2.javascript代码
function trigger(){
	var phoneNo = $("#phoneNo").val();
	if(phoneNo.length==11){
		var jsonUrl = '${web_root}/WalletPayChangeCard/getInfobyPhone/'+phoneNo;
		var userId = '';
		var xm = '';
		var idno = '';
		var cardno = '';
		var cardPhone = '';
	    $.ajax({
	        type: "POST",contentType:"application/json;charset=utf-8",url:jsonUrl,dataType:'json',success:function (response){  
	        	userId = response.userId;
	        	xm = response.xm;
	        	idno = response.idno;
	        	
	        },async : false
	    });
	    
	    $("#userId").val(userId);
	    $("#xm").val(xm);
	    $("#idno").val(idno);
	  
	}
};

</script>
3.java代码
@RequestMapping("/getInfobyPhone/{phoneNo}")
	public void getInfobyPhone(@PathVariable("phoneNo") String phoneNo,HttpServletRequest request,HttpServletResponse response)  {
		Request406008Entity req = new Request406008Entity();
		req.setPhoneNo(phoneNo);
		List<Request406008Entity> list = service.findAll(req);
        Request406008Entity obj = (Request406008Entity) list.get(0);
        try {
			response.getWriter().write(JSONArray.toJSONString(obj));
			response.getWriter().flush();
	        response.getWriter().close();
		} catch (IOException e) {
			e.printStackTrace();
		}
        
	}
结束!

猜你在找的Ajax相关文章