加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax后台数据校验简单Demo

发布时间:2020-12-16 01:52:05 所属栏目:百科 来源:网络整理
导读:先上代码: script type="text/javascript" src="./jquery-1.10.2.js"/scriptscript type="text/javascript"$(function() {$("#xxx").blur(function() { //失去焦点是使用var value = $("#xxx").val();$.ajax({url : "/Text_jQuerys/AjaxServlet",//请求服务

先上代码:

<script type="text/javascript" src="./jquery-1.10.2.js"></script>
<script type="text/javascript">
	$(function() {
		$("#xxx").blur(function() { //失去焦点是使用
			var value = $("#xxx").val();
			$.ajax({

				url : "/Text_jQuerys/AjaxServlet",//请求服务器
				//url : "http://localhost:8080/AjaxServlet",//请求服务器
				data : {
					//method : "ajax",val : value
				},//请求的参数 method=ajax val=xxx,服务器使用request。getParament()来获取
				async : true,//是否为异步请求
				cache : false,//是否缓存
				type : "post",dataType : "json",//服务器返回的类型
				success : function(result) { //执行成功时调用,result是服务器返回的值
					if (result)
						$("label").text("aaa");
					else
						$("label").text("vvv");
				}
			});
		});

	});
</script>
</head>
<body>
	姓名:
	<input name="name" type="text" id="xxx" />
	<label></label>
	<br /> 密码:
	<input name="age" type="text" />


</body>
Servlet代码:
	request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
	
		String value = request.getParameter("val");
		if (value.equals("qdmmy6")) {
			response.getWriter().print("true");
		}else {
			
			response.getWriter().print("false");
		}

	
匹配是否正确都会在输入框后边显示要打印的东西

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读