您的位置:首页 > 理论基础 > 计算机网络

如何在HTML页面中创建兼容不同浏览器的XMLHttpRequest对象

2015-05-20 17:12 961 查看
<?xml version="1.0" encoding="utf-8"?>

<!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" lang="en_US" xml:lang="en_US">

<!--

* Created on 2015-5-20

*

* To change the template for this generated file go to

* Window - Preferences - PHPeclipse - PHP - Code Templates

-->

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

<title> </title>

<script type="text/javascript">

var xmlhttp_request=false;

try{

if(window.ActiveXObject){

for(var i=5;i;i--){

try{

if($i==2){

xmlhttp_request=new ActiveXObject("Microsoft.XMLHTTP");

}else{

xmlhttp_request=new ActiveXObject("Msxml2.XMLHTTP."+i+".0");

xmlhttp_request.setRequestHeader("Content-Type","text/xml");

xmlhttp_request.setRequestHeader("Charset","utf-8");

}

break;

}catch(e){

xmlhttp_request=false;

}

}

}elseif(window.XMLHttpRequest){

xmlhttp_request=new XMLHttpRequest();

if(xmlhttp_request.overrideMimeType){

xmlhttp_request.overrideMimeType("text/xml");

}

}

}catch(e){

xmlhttp_request=false;

}

</script>

</head>

<body>

</body>

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