`
泥巴的艺术
  • 浏览: 5122 次
  • 性别: Icon_minigender_1
  • 来自: 成都
最近访客 更多访客>>
社区版块
存档分类
最新评论

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)类获取加解析
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics