Ajax中创建XMLHttpRequest对象
1.声明一个全局变量xmlHttp;
2.如果浏览器支持ActiveX对象,则使用ActiveX创建XMLHttpRequest对象;否则使用本地JavaScript对象来创建;
createxmlhttprequest.html:
程序代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>createXMLHttpRequest</title>
<script language="JavaScript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
alert("ActiveX Created!");
} else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
alert("JavaScript Created!");
}
}
</script>
</head>
<body οnlοad="createXMLHttpRequest();">
</body>
</html>
1.声明一个全局变量xmlHttp;
2.如果浏览器支持ActiveX对象,则使用ActiveX创建XMLHttpRequest对象;否则使用本地JavaScript对象来创建;
createxmlhttprequest.html:
程序代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>createXMLHttpRequest</title>
<script language="JavaScript">
var xmlHttp;
function createXMLHttpRequest(){
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
alert("ActiveX Created!");
} else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
alert("JavaScript Created!");
}
}
</script>
</head>
<body οnlοad="createXMLHttpRequest();">
</body>
</html>