My Ajax.js does not work in Mozilla Firefox

Discussion in 'JavaScript' started by piropeator, Oct 8, 2010.

  1. #1
    This is my Ajax.js, this code only work with IE8 or less but in Mozilla Firefox 3.6 doesn't work correctly.
    function getXMLHTTPRequest() {
    var req;
    try {
        req = new XMLHttpRequest();
    } catch(err1) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (err2) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (err3) {
                    req = false;
                }
            }
        }
        return req;
    }
    HTML:
    What is the mistake ?
     
    piropeator, Oct 8, 2010 IP
  2. gregishere

    gregishere Well-Known Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    116
    Digital Goods:
    4
    #2
    try adding this to your code:

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    req =new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    req =new ActiveXObject("Microsoft.XMLHTTP");
    }


     
    gregishere, Oct 8, 2010 IP