开发者

JavaScript mtree not working in Internet Explorer

One of my client had a form developed in component Mosets Tree. In the form when you select a main category it automatically displays the subcategories. Now the issue is; I had to hide some code to stop displaying a few things, after that the java script which was displaying subcategories after we select the main category is not working in IE.

code:

var xmlhttp;
function stateChanged(){
    if (xmlhttp.readyState==4) {
        document.getElementById("subCatId").innerHTML = xmlhttp.responseText;
    }
}

function fnGetSubCategory() {
    xmlhttp = GetXmlHttpObject();
    var new_cat_id = document.getElementById("new_cat_id").value;
    if (xmlhttp==null)
    {
        开发者_运维问答alert ("Browser does not support HTTP Request");
        return true;
    }

    var url="ps.php?cat_id="+new_cat_id;
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);

}

function GetXmlHttpObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    }
 
    if (window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
 
} 
 

It is working fine in all other browsers.

Thanks in advance.


Try creating the object xmlHttp with this code:

function createXmlHttpRequestObject(){
var xmlHttp;
try{
        xmlHttp = new XMLHttpRequest();
}
catch (e) {

    // If its IE 6 or other version before

    var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0','MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP');

    // We try all versions

    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
        try {

            //Try creating xmlHttp object

            xmlHttp = new ActiveXObject(XmlHttpVersions[i]); 
        }
        catch (e){
            xmlHttp = false;
        }
    }
}

// If object doesn't exist sends error

if (!xmlHttp){
    alert("Error creating XMLHttpRequest object");
}

else{
    return xmlHttp;
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜