Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code work fine in IE but not firefox 1.5.0.6 - XMLHttpRequest

Status
Not open for further replies.

jtrembla

ISP
Joined
Jul 6, 2006
Messages
104
Location
US
Does anyone know why this is, I am pretty sure I handled this in my if statement checking for browser type. I presume this is a bug? Anyone know of a workaround?

here is my code

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
    
	function makeRequest(url) {
        var http_request = false;
		// Mozilla, Safari
        if (window.XMLHttpRequest) { 
           http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
               http_request.overrideMimeType('text/xml');
                
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() { alertContents(http_request); };
        http_request.open('GET', url, true);
        http_request.send(null);

    }

    function alertContents(http_request) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				
				// This is were we handle the response
                var xmldoc = http_request.responseXML;
				var myNodes = xmldoc.getElementsByTagName('department')
				
				//Extract Values using loop
   				for(var counter=0;counter<myNodes.length;counter++) {
   					var textvalue;
      				textvalue = myNodes.item(counter).firstChild.nodeValue;
					addOption(textvalue,"");
	 			}
				
              } else {
                alert('There was a problem with the request.');
            }
        }

    }
	
	
// Function to Add Items to ListBox	
function addOption(text, value) {
document.getElementById("department_list").add(new Option(text, value));
}

</script>


</head>

<body onload="makeRequest('dept.xml')">

<form action="">
<div>
<select name="department_list">
<option>Dept list</option>
</select>
</div>
</form>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top