Ajax request ERROR on IE

Posted by tinti on Stack Overflow See other posts from Stack Overflow or by tinti
Published on 2010-06-16T09:14:49Z Indexed on 2010/06/16 9:22 UTC
Read the original article Hit count: 160

Filed under:
|

Hello all! I have a small problem on IE browser (actually on Google Chrome too) I have this js code

function createDoc(url) {
    var xhttp = ajaxRequest();
    var currentLocationBase = window.location.href;
    currentLocationBase = currentLocationBase.substr(0,currentLocationBase.lastIndexOf("/") + 1);
    var u  = currentLocationBase + url;

    xhttp.open("GET", u, false);
    xhttp.send(null);

    var xml = xhttp.responseXML;
    return xml;
}

/**
* Builds an AJAX reques handler.
*
* @return The handler.
*/
function ajaxRequest() {
    var xhttp = null;
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    } else if (window.ActiveXObject){     
        // Internet Explorer 5/6
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
    }
    return xhttp;
}

In Firefox this code works great, but not in IE and Google Chrome Seems that the error is given at the line

xhttp.open("GET", u, false);

Can anyone help me to understand what i'm doing wrong? Thanks

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about AJAX