Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在没有jQuery的情况下处理Ajax浏览器兼容性?_Javascript_Ajax - Fatal编程技术网

Javascript 如何在没有jQuery的情况下处理Ajax浏览器兼容性?

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",

我有如下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", "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();     
    }

您有什么兼容性问题?实际上值得一看。我很感激。