开发者

Error showing unknown name in javascript

开发者 https://www.devze.com 2023-02-10 21:03 出处:网络
wen i select an option from drop down box, onchange functionality is called which has the functin retrieveurl(url,formbean); code written.

wen i select an option from drop down box, onchange functionality is called which has the functin retrieveurl(url,formbean); code written.

It calls the ajax written in javascript and its not able to detect my ver开发者_如何学JAVAsion of browser i.e IE6.0.2900....

below code i have used...

try {

  req = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

   try {

      req = new ActiveXObject("Microsoft.XMLHTTP");

   } catch {

       alert('second catch');
   }

}

wen i debug it comes to the second catch alert

can anyone help me on this??


As far as I know this should work on IE6. But you are missing a (e) argument in the second catch, which probably should be there. Maybe this is messing things up? Sorry I can't check, no IE6.


Missed catch*(e)* in second catch-statement

try
{
    req = new ActiveXObject("Msxml2.XMLHTTP");
}

catch(e)
{
    try
    {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }

    catch(e)
    {
        alert('second catch');
    }
}

UPDATE: I would also suggest to use ALL version of MS XML HTTP object

function getHTTPRequest () 
{
    var xmlHttp;
    try 
    {
        // Firefox, Chrome, Opera, IE 8
        xmlHttp = new XMLHttpRequest();
    } 
    catch (err) 
    {
        // IE and possible XML HTTP ProIDs
        var XmlHttpVersions = new Array(
                            "Msxml2.XMLHTTP.7.0",
                            "Msxml2.XMLHTTP.6.0",
                            "Msxml2.XMLHTTP.5.0",
                            "Msxml2.XMLHTTP.4.0",
                            "MSXML2.XMLHTTP.3.0",
                            "MSXML2.XMLHTTP",
                            "Microsoft.XMLHTTP"
                            );
        for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
        {
            try 
            {
                xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
            }
            catch(err) {} //Ignore


        }        
    }

    if(!xmlHttp) 
    {
        alert("No HttpRequest supported");
    }
    else 
    {
        return xmlHttp;
    }
}

var xhr = getHTTPRequest();
0

精彩评论

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