ajax(4)--post

<script type="text/javascript">
window.onload = function () {
gel("btnReg").onclick = function () {
//1.创建异步对象
var xhr = createXmlHttp();
//2.准备请求的url和参数
var urlPara = "05Reg.ashx";
//3.设置异步对象的请求参数
xhr.open("post", urlPara, true);
//4.如果是post方式的话,为请求报文头中 添加 Content-Type 来设置参数的编码组织方式
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//5.设置回调函数
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
//接收返回值
var res = xhr.responseText;
if (res == "ok") {
alert("恭喜您,注册成功!");
} else {
alert("对不起,注册失败!");
}
}
};
//6.发送请求 name=james&pwd=123
xhr.send("name=" + gel("txtName").value + "&pwd=" + gel("txtPwd").value);
};
};
</script>

posted @ 2014-05-14 22:16  步子521  阅读(192)  评论(0编辑  收藏  举报