微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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();
		}
        
	}
结束!

原文地址:https://www.jb51.cc/ajax/160941.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐