AJAX + JQuery 异步请求

这里实现简单的登录异步请求

1.send.js,需要在html页面中加入JQuery库

function send()
{
	alert("in send()");
	var user = document.getElementById("name").value;
	var psw = document.getElementById("password").value;
	alert(user);
	alert(psw);
	$.ajax({
					type:"POST",
					contentType:"application/x-www-form-urlencoded;charset=UTF-8",
					url:'test',
					data:{
					userName:user,
					password:psw
				},
				
				dataType:'json',
				
				success:function(result){
				var status = result.status;
				var message = result.message;
				if(-1 == status)
				{
					alert("用户不存在");
				}
				else if(-2 == status)
				{
					alert("密码错误");
				}
				else
				{
					alert("登录成功");
					window.location.href="home.htm";
				}
			}
		}
	);
}

      后台就不记录了,反正就是从后台传来了JSon数据,通过function(result)类获取加解析

猜你喜欢

转载自569425720.iteye.com/blog/1770844