您的位置:首页 > 其它

1215整理

2015-12-16 19:54 225 查看
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

<script language="javascript" >

//IE
//var h= new ActiveXObject("Msxml2.XMLHTTP");

//var p= new ActiveXObject("Microsoft.XMLHTTP");

//非IE
//var f = new XMLHTTPRequest();

//通用代码
var hx;

if(window.XMLHttpRequest)//非IE,IE7及以上
{
hx= new XMLHttpRequest();

alert("以new XMLHttpRequest()形式创建");
}
else if(window.ActiveXObject) //IE
{
try
{
hx= new ActiveXObject("Msxml2.XMLHTTP");

alert("以Msxml2.XMLHTTP形式创建");
}
catch(e)
{
alert(e);

try
{
hx= new ActiveXObject("Microsoft.XMLHTTP");

alert("以Microsoft.XMLHTTP形式创建");
}
catch(e)
{
alert(e);
}
}
}

if(!hx)
{
alert("创建XMLHttpRequest失败");
}
else
{
alert("创建XMLHttpRequest成功");
}

//1.设置异步请求的URL等信息     请求方法,URL,请求方式(是否异步)
hx.open("POST","ajaxTest",true);

//2.设置回调函数,事件处理器
hx.onreadystatechange = getResult;

//get
//hx.send(null);

hs.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

//post
hx.send("userid=abc");

//alert("Server" + hx.getAllResponceHeaders("Server"));

function getResult()
{
//1-判断请求状态
//alert("readyState=" + hx.readyState);

if (hx.readyState == 4)
{
if (hx.status == 200)
{
alert("回调信息=" + hx.responseText)
}
else
{
alert("错误代码=" + hx.status + "" + hx.statusText);
}
}
}

</script>
</head>

<body>
</body>
</html>


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: