如何在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>
<!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>
相关文章推荐
- 兼容不同版本浏览器及版本号来创建XMLHttpRequest对象
- 创建ajax对象及解决不同浏览器对XMLHttpRequest对象的兼容问题
- 解析ajax核心XMLHTTPRequest对象的创建与浏览器的兼容问题
- 不同浏览器创建 XMLHttpRequest 对象的方法
- 创建针对不同浏览器的XMLHttpRequest对象,异步校验
- 解析ajax核心XMLHTTPRequest对象的创建与浏览器的兼容问题
- 为不同浏览器创建XMLHttpRequest对象
- JS不同浏览器创建xmlhttprequest对象的方法
- 解析ajax核心XMLHTTPRequest对象的创建与浏览器的兼容问题
- 解析ajax核心XMLHTTPRequest对象的创建与浏览器的兼容问题
- 不同浏览器创建XMLHttpRequest对象
- 关于浏览器创建XMLHttpRequest对象
- Ajax(判断浏览器创建XMLHttpRequest对象)
- AJAX不同浏览器的XMLHttpRequest对象生成
- 以支持多种浏览器的方式创建 XMLHttpRequest 对象
- 以支持多种浏览器的方式创建 XMLHttpRequest 对象
- 如何创建XMLHttpRequest对象
- 如何在页面中嵌入plugin对象(兼容不同浏览器)
- 如何创建XMLHttpRequest对象
- ajax基础(一):创建适合不同浏览器的XMLHttpRequest