CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Posts
    2

    another Firefox problem

    I have been looking at other posts about Firefox and AJAX. I haven't found anything that will solve my problem.... not anything I've noticed anyways. My code works perfectly in IE but not Firefox. I am using version 2.0

    here is my code
    PHP Code:
    <script language="javascript" type="text/javascript">
    var 
    XMLHttpRequestObject false;
    try{
        
    XMLHttpRequestObject = new ActiveXObject("MSXML2.XMLHTTP");
        } catch(
    exception1) {
            try{
                
    XMLHttpRequestObject = new ActiveXObject("Microsoft");
                } catch(
    exception2) {
                    
    XMLHttpRequestObject false;
                    }
            } 

    if(
    XMLHttpRequestObject && window.XMLHttpRequest) {
        
    XMLHttpRequestObject = new XMLHttpRequest();
        }
        
    function 
    getValue(cat,id) {
        
    clearList(cat,id);
        
    getSub(cat,id);
        } 
        
    function 
    getSub(cat,id) {
        if(
    XMLHttpRequestObject) {
            if(
    cat == "Electronics") {
                
    XMLHttpRequestObject.open("GET","electronics.xml",true);
                }
            if(
    cat == "Medical") {
                
    XMLHttpRequestObject.open("GET","medical.xml",true);
                }
            if(
    cat == "Industrial") {
                
    XMLHttpRequestObject.open("GET","industrial.xml",true);
                }
            if(
    cat == "Nanotechnology") {
                
    XMLHttpRequestObject.open("GET","nano.xml",true);
                }
            
    alert(cat);
            var 
    subId id;
            
            
    XMLHttpRequestObject.onreadystatechange = function() {
                if(
    XMLHttpRequestObject.readyState == && XMLHttpRequestObject.status == 200) {
                    var 
    xmlDocument XMLHttpRequestObject.responseXML;
                    
                    var 
    subCategory xmlDocument.getElementsByTagName("subs");
                    
    listSubs(subCategory,subId);
                    }
                }
            
    XMLHttpRequestObject.send(null);
            }
        }
        
    function 
    listSubs(subCategory,subId) {
        var 
    loopIndex;
        var 
    subCat;
        if(
    subId == "mainCat1") {
            
    subCat "subCat1";
            }
        if(
    subId == "mainCat2") {
            
    subCat "subCat2";
            }
        var 
    selectControl document.getElementById(subCat);
        
        for(
    loopIndex=0;loopIndex<subCategory.length;loopIndex++) {
            
    selectControl.options[loopIndex] = new
                
    Option(subCategory[loopIndex].firstChild.data);
            }
        }
        
    function 
    clearList(cat,id) {
        var 
    clearCat;
        if(
    id == "mainCat1") {
            
    clearCat "subCat1";
            }
        if(
    id == "mainCat2") {
            
    clearCat "subCat2";
            }
        var 
    len document.getElementById(clearCat).options.length
          
    for(0leni++) {
            
    document.getElementById(clearCat).options[0] = null;
            }
        }
    </
    script
    I hope someone can spot something. Thanks for your help.

  2. #2
    Join Date
    Nov 2006
    Posts
    2

    Re: another Firefox problem

    I got it to work! lol... instead of sitting there and reading each line of code again, I just started going in and changing different things and finally came across the one change that made it work.

    here is the change I made:

    I first had this
    PHP Code:
    if(XMLHttpRequestObject && window.XMLHttpRequest) {
        
    XMLHttpRequestObject = new XMLHttpRequest();
        } 
    I took out the XMLHttpRequestObject and ended with this

    PHP Code:
    if(window.XMLHttpRequest) {
        
    XMLHttpRequestObject = new XMLHttpRequest();
        } 
    and now it seems to work. Thanks anyways

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured