完美兼容I
来源:互联网 发布:网络拓扑层级 编辑:程序博客网 时间:2024/04/30 01:38
Js代码
function Ajax(){
this.httpXML=false;
this.init();
}
Ajax.prototype.init=function(){
if(window.XMLHttpRequest){
this.httpXML=new XMLHttpRequest();
if (this.httpXML.overrideMimeType){
this.httpXML.overrideMimeType("text/xml");
}
}else if(window.ActiveXObject){
try{this.httpXML = new ActiveXObject("Msxml2.XMLHTTP");}catch (e){
try{this.httpXML = new ActiveXObject("Microsoft.XMLHTTP");}catch (e){}
}
}
if(!this.httpXML){
window.alert("can't create XMLHttpRequest object");
return null;
}
}
Ajax.prototype.send=function(_method,_url,_data,_callback){
this.httpXML.onreadystatechange=function(){
if(this.readyState==4&&this.status==200){
_callback.call(this,this.responseText);
}
}
if (_method.toLowerCase() == "get"){
//if(navigator.userAgent.indexOf("MSIE")<=0){
// netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
//}
this.httpXML.open(_method, _url, true);
this.httpXML.send(null);
}else if (_method.toLowerCase() == "post"){
this.httpXML.open(_method, _url, true);
this.httpXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.httpXML.send(_data);
}
}
Ajax.prototype.callback=function(){
}
function Ajax(){
this.httpXML=false;
this.init();
}
Ajax.prototype.init=function(){
if(window.XMLHttpRequest){
this.httpXML=new XMLHttpRequest();
if (this.httpXML.overrideMimeType){
this.httpXML.overrideMimeType("text/xml");
}
}else if(window.ActiveXObject){
try{this.httpXML = new ActiveXObject("Msxml2.XMLHTTP");}catch (e){
try{this.httpXML = new ActiveXObject("Microsoft.XMLHTTP");}catch (e){}
}
}
if(!this.httpXML){
window.alert("can't create XMLHttpRequest object");
return null;
}
}
Ajax.prototype.send=function(_method,_url,_data,_callback){
this.httpXML.onreadystatechange=function(){
if(this.readyState==4&&this.status==200){
_callback.call(this,this.responseText);
}
}
if (_method.toLowerCase() == "get"){
//if(navigator.userAgent.indexOf("MSIE")<=0){
// netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
//}
this.httpXML.open(_method, _url, true);
this.httpXML.send(null);
}else if (_method.toLowerCase() == "post"){
this.httpXML.open(_method, _url, true);
this.httpXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
this.httpXML.send(_data);
}
}
Ajax.prototype.callback=function(){
}
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" >
<head>
<title>完美兼容IE、FF、Opera浏览器</title>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript">
function send(){
ajax=new Ajax();
ajax.send("get","listener/Hajax.ashx","post测试请求",ddd);
}
function ddd(data){
alert(data);
}
</script>
</head>
<body>
<button onclick="send()">测试</button>
</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" >
<head>
<title>完美兼容IE、FF、Opera浏览器</title>
<script type="text/javascript" src="js/ajax.js"></script>
<script type="text/javascript">
function send(){
ajax=new Ajax();
ajax.send("get","listener/Hajax.ashx","post测试请求",ddd);
}
function ddd(data){
alert(data);
}
</script>
</head>
<body>
<button onclick="send()">测试</button>
</body>
</html>
- 完美兼容I
- webDriver + Firefox 浏览器 完美兼容
- i touch 4完美越狱
- CSS 弹出菜单, 完美实现, 完美兼容 By shawl.qiu
- XML4C完美兼容中文的补充
- XML4C完美兼容中文的补充
- CSS完美兼容IE6IE7FF的通用方法
- 完美退出Android程序(兼容所有SDK)
- DX11可以完美兼容于DX10显卡
- 返回顶部JS(完美兼容IE6)
- 完美解决IE兼容模式问题
- 完美解决IE兼容模式问题
- 完美解决IE兼容模式问题
- Windows 10 国庆首发 联软首家完美兼容!
- 完美解决IE6不能兼容position:fixed
- 完美解决IE6不能兼容position:fixed
- ecshop 兼容jquery 最完美的解决方案
- JavaScript原生下拉菜单完美兼容IE
- encodeURIcomponent编码和ASP.NET之间编码转换
- 利用腾讯的ip地址库做ip地址定位
- max插件编译相关
- MTK
- Wow! Even Microsoft uses AutoESL's C synthesis to speed up its SW
- 完美兼容I
- 谈谈对软件开发过程的认识
- 大家好
- ajax驱动
- C++指针与引用
- AutoESL at DAC 2010: High-level Synthesis for ASICs and FPGAs
- DOS批量删除多余后缀名
- Silverlight升级后无法调试项目的解决方法
- c++继承与多态