Hi guys, I frequently visit this site to get answers to my problems and this one is really getting to me...
I have a page that allows you to Browse Authors. There are three drop down boxes that auto-populate via AJAX. I have a file which it [javascript] calls and returns the dynamically built XML file in the boxes Nationality, Ethnicity, and Race.
My problem? It works in FireFox, it works in IE7, but not in IE6; it returns the error "Cannot create XMLHTTP instance."
I would link you to the page http://www.alexanderstreet6.com/wols...x?byLetter=all
but i'm not sure if you'll be able to see it (passworded since it's in QA)
Here is my code:
HTML CODE:
Expand|Select|Wrap|Line Numbers
- <body onload="javascript: AutoLoadDropDowns();">
- ...
- <script type="text/javascript">
- function AutoLoadDropDowns()
- {
- var qs = window.location.toString().substring(window.location.toString().indexOf("?"));
- var ele1 = document.getElementById('selNationality');
- var ele2 = document.getElementById('selEthnicity');
- var ele3 = document.getElementById('selRace');
- if (ele1 != null)
- do_xml('xml/xml.generate.nationalities.aspx', 'selNationality', 'nationalities', qs);
- if (ele2 != null)
- do_xml('xml/xml.generate.ethnicities.aspx', 'selEthnicity', 'ethnicities', qs);
- if (ele3 != null)
- do_xml('xml/xml.generate.races.aspx', 'selRace', 'races', qs);
- }
- </script>
- ...
- <select class="inputSubmit" id="selNationality" onchange="javascript:changevalue(this);" name="selNationality" style="width:150px;">
- <option value="<%=ChangeValue(Request.RawUrl.ToString(), "nationality", "", 1)%>">author nationality</option>
- </select>
- <select class="inputSubmit" id="selEthnicity" onchange="javascript:changevalue(this);" name="selEthnicity" style="width:150px;">
- <option value="<%=ChangeValue(Request.RawUrl.ToString(), "ethnicity", "", 1)%>">author ethnicity</option>
- </select>
- <select class="inputSubmit" id="selRace" onchange="javascript:changevalue(this);" name="selRace" style="width:150px;">
- <option value="<%=ChangeValue(Request.RawUrl.ToString(), "race", "", 1)%>">author race</option>
- </select>
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript" language="javascript">
- var notWhitespace = /\S/
- function cleanWhitespace(node)
- {
- for (var x = 0; x < node.childNodes.length; x++)
- {
- var childNode = node.childNodes[x]
- if ((childNode.nodeType == 3) && (!notWhitespace.test(childNode.nodeValue)))
- {
- // that is, if it's a whitespace text node
- node.removeChild(node.childNodes[x])
- x--
- }
- if (childNode.nodeType == 1)
- {
- // elements can have text child nodes of their own
- cleanWhitespace(childNode)
- }
- }
- }
- var http_request1 = null;
- var http_request2 = null;
- var http_request3 = null;
- function GetXmlHttpObject()
- {
- var xmlHttp = null;
- if (window.XMLHttpRequest)
- {
- xmlHttp = new XMLHttpRequest(); // Mozilla, Safari,...
- if (xmlHttp.overrideMimeType)
- {
- xmlHttp.overrideMimeType('text/xml');
- }
- else if (window.ActiveXObject)
- {
- try
- {
- xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // IE
- }
- catch (e)
- {
- try
- {
- xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE
- }
- catch (e)
- {
- // do nothing
- }
- }
- }
- return xmlHttp;
- }
- }
- function makeRequest(url, objectname, rootname, qs)
- {
- if (rootname == 'nationalities')
- {
- http_request1 = GetXmlHttpObject();
- if (http_request1 == null)
- {
- alert('Cannot create XMLHTTP instance');
- return false;
- }
- else
- {
- http_request1.onreadystatechange = alertContents1;
- http_request1.open('GET', url + qs, true);
- http_request1.send(null);
- }
- }
- if (rootname == 'ethnicities')
- {
- http_request2 = GetXmlHttpObject();
- if (http_request2 == null)
- {
- alert('Cannot create XMLHTTP instance');
- return false;
- }
- else
- {
- http_request2.onreadystatechange = alertContents2;
- http_request2.open('GET', url + qs, true);
- http_request2.send(null);
- }
- }
- if (rootname == 'races')
- {
- http_request3 = GetXmlHttpObject();
- if (http_request3 == null)
- {
- alert('Cannot create XMLHTTP instance');
- return false;
- }
- else
- {
- http_request3.onreadystatechange = alertContents3;
- http_request3.open('GET', url + qs, true);
- http_request3.send(null);
- }
- }
- }
- function alertContents1()
- {
- if (http_request1.readyState == 4)
- {
- if (http_request1.status == 200)
- {
- var xmldoc = http_request1.responseXML;
- cleanWhitespace(xmldoc);
- var root;
- root = xmldoc.getElementsByTagName('nationalities').item(0);
- var arr1 = new Array(root.childNodes.length);
- var arr2 = new Array(root.childNodes.length);
- for (var iNode = 0; iNode < root.childNodes.length; iNode++)
- {
- var node = root.childNodes[iNode]
- arr1[iNode] = node.childNodes[0].childNodes[0].nodeValue;
- arr2[iNode] = node.childNodes[1].childNodes[0].nodeValue;
- }
- addrow('selNationality', arr1, arr2);
- if (document.getElementById('selNationality').options.length < 3)
- {
- document.getElementById('selNationality').style.display = "none";
- }
- }
- else
- {
- alert('There was a problem with the request.');
- }
- }
- }
- function alertContents2()
- {
- if (http_request2.readyState == 4)
- {
- if (http_request2.status == 200)
- {
- var xmldoc = http_request2.responseXML;
- cleanWhitespace(xmldoc);
- var root;
- root = xmldoc.getElementsByTagName('ethnicities').item(0);
- var arr1 = new Array(root.childNodes.length);
- var arr2 = new Array(root.childNodes.length);
- for (var iNode = 0; iNode < root.childNodes.length; iNode++)
- {
- var node = root.childNodes[iNode]
- arr1[iNode] = node.childNodes[0].childNodes[0].nodeValue;
- arr2[iNode] = node.childNodes[1].childNodes[0].nodeValue;
- }
- addrow('selEthnicity', arr1, arr2);
- if (document.getElementById('selEthnicity').options.length < 3)
- {
- document.getElementById('selEthnicity').style.display = "none";
- }
- }
- else
- {
- alert('There was a problem with the request.');
- }
- }
- }
- function alertContents3()
- {
- if (http_request3.readyState == 4)
- {
- if (http_request3.status == 200)
- {
- var xmldoc = http_request3.responseXML;
- cleanWhitespace(xmldoc);
- var root;
- root = xmldoc.getElementsByTagName('races').item(0);
- var arr1 = new Array(root.childNodes.length);
- var arr2 = new Array(root.childNodes.length);
- for (var iNode = 0; iNode < root.childNodes.length; iNode++)
- {
- var node = root.childNodes[iNode]
- arr1[iNode] = node.childNodes[0].childNodes[0].nodeValue;
- arr2[iNode] = node.childNodes[1].childNodes[0].nodeValue;
- }
- addrow('selRace', arr1, arr2);
- if (document.getElementById('selRace').options.length < 3)
- {
- document.getElementById('selRace').style.display = "none";
- }
- }
- else
- {
- alert('There was a problem with the request.');
- }
- }
- }
- function changevalue(ele)
- {
- window.location = ele.options[ele.selectedIndex].value;
- }
- function do_xml(scriptname, objectname, rootname, qs)
- {
- if (rootname == "nationalities")
- {
- document.getElementById('selNationality').onclick = "";
- }
- if (rootname == "ethnicities")
- {
- document.getElementById('selEthnicity').onclick = "";
- }
- if (rootname == "races")
- {
- document.getElementById('selRace').onclick = "";
- }
- makeRequest(scriptname, objectname, rootname, qs);
- }
- function addrow(objectname, arr1, arr2)
- {
- var dropdown = document.getElementById(objectname);
- for (r = 0; r < arr1.length; r++)
- {
- var txt = arr1[r];
- var val = arr2[r];
- var newOpt;
- if (objectname == "selNationality")
- {
- if (Url.decode(getQueryVariable("nationality")).replace( /\+/g, " " ) == txt)
- {
- newOpt = new Option(txt, val, true, true);
- }else{
- newOpt = new Option(txt, val, false, false);
- }
- }
- if (objectname == "selEthnicity")
- {
- if (Url.decode(getQueryVariable("ethnicity")).replace( /\+/g, " " ) == txt)
- {
- newOpt = new Option(txt, val, true, true);
- }else{
- newOpt = new Option(txt, val, false, false);
- }
- }
- if (objectname == "selRace")
- {
- if (Url.decode(getQueryVariable("race")).replace( /\+/g, " " ) == txt)
- {
- newOpt = new Option(txt, val, true, true);
- }else{
- newOpt = new Option(txt, val, false, false);
- }
- }
- dropdown.options[dropdown.options.length] = newOpt;
- }
- }
- function getQueryVariable(variable) {
- var query = window.location.search.substring(1);
- var vars = query.split("&");
- for (var i=0;i<vars.length;i++) {
- var pair = vars[i].split("=");
- if (pair[0] == variable) {
- if (pair[1].toString().trim() == ""){
- return null;
- }else{
- return pair[1];
- }
- }
- }
- }
- String.prototype.trim = function() {
- a = this.replace(/^\s+/, '');
- return a.replace(/\s+$/, '');
- };
- </script>
cheers!
- John West