Javascript 如何在没有jQuery的情况下处理Ajax浏览器兼容性?
我有如下js函数Javascript 如何在没有jQuery的情况下处理Ajax浏览器兼容性?,javascript,ajax,Javascript,Ajax,我有如下js函数 //getting element by id function _(x){ return document.getElementById(x); } //ajax request handling function ajaxObj( meth, url ) { var x = new XMLHttpRequest(); x.open( meth, url, true ); x.setRequestHeader("Content-type",
//getting element by id
function _(x){
return document.getElementById(x);
}
//ajax request handling
function ajaxObj( meth, url ) {
var x = new XMLHttpRequest();
x.open( meth, url, true );
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
return x;
}
function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
return true;
}
}
如何在没有jQuery的情况下处理浏览器兼容性?如果你用谷歌搜索它,有很多不同的选择,但我在以下网站找到了一个: 基本的想法是我认为你会发现有用的,关于他们如何决定使用哪个类
var oXMLHttpRequest = window.XMLHttpRequest;
// Define on browser type
var bGecko = !!window.controllers;
var bIE = !!window.document.namespaces;
var bIE7 = bIE && window.navigator.userAgent.match(/MSIE 7.0/);
// Enables "XMLHttpRequest()" call next to "new XMLHttpRequest()"
function fXMLHttpRequest() {
if (!window.XMLHttpRequest || bIE7) {
this._object = new window.ActiveXObject("Microsoft.XMLHTTP");
} // only use initial XHR object internally if current reference to XHR is our normalized replacement
else if (window.XMLHttpRequest.isNormalizedObject) {
this._object = new oXMLHttpRequest();
} // otherwise use whatever is currently referenced by XMLHttpRequest
else {
this._object = new window.XMLHttpRequest();
}
您有什么兼容性问题?实际上值得一看。我很感激。