XMLHttpRequest和ActiveXObject学习
程序员文章站
2022-12-08 14:34:52
//var xmlHttpReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");
//定义变量,存储对象
var xmlHttp;
//...
//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 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);
}
}
}
上一篇: 数据分表小结
推荐阅读
-
类型和变量(C#学习笔记02)
-
C#事件和委托(C#学习笔记03)
-
值得分享和收藏的xmlplus组件学习教程
-
Python中Random和Math模块学习笔记
-
我在学习网络营销的体会和收获
-
Sql学习第一天——SQL UNION 和 UNION ALL 操作符认识
-
IOS UI学习教程之区分NSBundle和NSURL(读取文件、写入文件)
-
Python ORM框架SQLAlchemy学习笔记之数据添加和事务回滚介绍
-
python网络编程学习笔记(七):HTML和XHTML解析(HTMLParser、BeautifulSoup)
-
Python ORM框架SQLAlchemy学习笔记之安装和简单查询实例