完美兼容IE、FF、Opera的Ajax类支持get、post、自定义回调函数
2011-03-18 14:26
603 查看
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"){ 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); } }//===========================================function getResult(data){alert(data);}new Ajax().send('post','url','a=1&b=2',getResult);
相关文章推荐
- 转载一个完美兼容IE、FF、Opera的Ajax类支持get、post、自定义回调函数
- 自定义浏览器滚动条的样式,打造属于你的滚动条风格——兼容IE和webkit(ff不支持)
- 为何firefox不支持insertRow和insertCell。我如何能让firefox显示和ie显示的效果一样?iframe实现高度自适应,兼容FF、Opera、Safari
- [练习]自定义checkbox效果 兼容ie ff opera
- 自定义浏览器滚动条的样式,打造属于你的滚动条风格——兼容IE和webkit(ff不支持)
- js自定义滚动条完美兼容ff,IE
- [举一反三]解决IE下select标签innerHTML插入option的BUG(兼容IE,FF,Opera,Chrome,Safari) 前言: 这是一个老bug了,现在提供一个完美解决方案。由于我一直是用createElement来创建动态的op
- js实现的非跨域的iframe高度自适应(完美兼容IE,FF,Opera)
- 完美Ajax类,支持事件,支持容器,支持多种操作方式,兼容ie,firefox http://bbs.51js.com/thread-65023-1-1.html
- js 自定义getClass函数实现获取dom的class 兼容火狐ie
- 完美兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面js代码
- 兼容IE和FF的手动触发事件,并自定义Event的属性值
- [完美]原生JS获取浏览器版本判断--支持Edge,IE,Chrome,Firefox,Opera,Safari,以及各种使用Chrome和IE混合内核的浏览器
- IE不支持getElementsByClassName最终完美解决方案
- Ajax类,支持事件,容器,多种操作方式,兼容ie,firefox
- 真正的iframe高度自适应(兼容IE,FF,Opera)
- JS拖动层(支持ie,ff,opera,safari)
- 自定义document.getElementsByName() 兼容IE Firfox
- 兼容 ie,ff,Google,safari,opera 的回车事件
- IE不支持getElementsByClassName最终完美解决方案