XMLHttpRequest和ActiveXObject学习
导读:收集整理的这篇文章主要介绍了html5教程-XMLHttpRequest和ActiveXObject学习,觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过...
收集整理的这篇文章主要介绍了html5教程-XMLHttpRequest和ActiveXObject学习,觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。 //VAR XMlHttPReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
//定义变量,存储对象
var xmlHttp;
// 创建XMLHttpRequest对象
if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
}
xmlHttpReq.oPEn("GET", "https://localhost:9090/html5/test", false);
xmlHttpReq.onreadystatechange = handleStateChange;
xmlHttpReq.send();
// xmlHttpReq.responseText
// xmlHttpReq.responseXML
var htmlObj = "";
htmlObj += "=============状态码=================
";
htmlObj += "status=" + xmlHttpReq.status + "
";
htmlObj += "statusText=" + xmlHttpReq.statusText + "
";
htmlObj += "=============头信息=================
";
htmlObj += "heads=" + xmlHttpReq.getAllResponseHeaders() + "
";
htmlObj += "Content-Length=" + xmlHttpReq.getResponseHeader("Content-Length") + "
";
htmlObj += "=============返回信息=================
";
htmlObj += "responseStream=" + xmlHttpReq.responseStream + "
";
var obj = document.getElementById("showDiv");
obj.innerHTML = htmlObj;
function handleStateChange() {
// 请求的状态有5个值:0=未初始化;1=正在加载;2=已经加载;3=交互中;4=完成;
if (xmlHttpReq.readyState == 4) {
// 200对应OK,如404=未找到网页
if (xmlHttpReq.status == 200) {
// alert(xmlHttpReq.responseText);
}
}
} //var xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
//定义变量,存储对象
var xmlHttp;
// 创建XMLHttpRequest对象
if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
}
xmlHttpReq.open("GET", "https://localhost:9090/html5/test", false);
xmlHttpReq.onreadystatechange = handleStateChange;
xmlHttpReq.send();
// xmlHttpReq.responseText
// xmlHttpReq.responseXML
var htmlObj = "";
htmlObj += "=============状态码=================
";
htmlObj += "status=" + xmlHttpReq.status + "
";
htmlObj += "statusText=" + xmlHttpReq.statusText + "
";
htmlObj += "=============头信息=================
";
htmlObj += "heads=" + xmlHttpReq.getAllResponseHeaders() + "
";
htmlObj += "Content-Length=" + xmlHttpReq.getResponseHeader("Content-Length") + "
";
htmlObj += "=============返回信息=================
";
htmlObj += "responseStream=" + xmlHttpReq.responseStream + "
";
var obj = document.getElementById("showDiv");
obj.innerHTML = htmlObj;
function handleStateChange() {
// 请求的状态有5个值:0=未初始化;1=正在加载;2=已经加载;3=交互中;4=完成;
if (xmlHttpReq.readyState == 4) {
// 200对应OK,如404=未找到网页
if (xmlHttpReq.status == 200) {
// alert(xmlHttpReq.responseText);
}
}
}
觉得可用,就经常来吧! 欢迎评论哦! html5教程,巧夺天工,精雕玉琢。小宝典献丑了!
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: XMLHttpRequest和ActiveXObject学习
本文地址: https://pptw.com/jishu/586384.html