473,570 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot create XMLHTTP instance in IE6?

3 New Member
If I possessed the power to sway the mind of every user in the world to delete all forms of Internet Explorer I would die a happy man.

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
  1. <body onload="javascript: AutoLoadDropDowns();">
  2. ...
  3. <script type="text/javascript">
  4.     function AutoLoadDropDowns()
  5.     {
  6.         var qs = window.location.toString().substring(window.location.toString().indexOf("?"));
  7.  
  8.         var ele1 = document.getElementById('selNationality');
  9.         var ele2 = document.getElementById('selEthnicity');
  10.         var ele3 = document.getElementById('selRace');
  11.  
  12.         if (ele1 != null)
  13.             do_xml('xml/xml.generate.nationalities.aspx', 'selNationality', 'nationalities', qs);
  14.  
  15.         if (ele2 != null)
  16.             do_xml('xml/xml.generate.ethnicities.aspx', 'selEthnicity', 'ethnicities', qs);
  17.  
  18.         if (ele3 != null)
  19.             do_xml('xml/xml.generate.races.aspx', 'selRace', 'races', qs);
  20.     }
  21.     </script>
  22. ...
  23. <select class="inputSubmit" id="selNationality" onchange="javascript:changevalue(this);" name="selNationality" style="width:150px;">
  24.                 <option value="<%=ChangeValue(Request.RawUrl.ToString(), "nationality", "", 1)%>">author nationality</option>
  25.             </select>
  26.             <select class="inputSubmit" id="selEthnicity" onchange="javascript:changevalue(this);" name="selEthnicity" style="width:150px;">
  27.                 <option value="<%=ChangeValue(Request.RawUrl.ToString(), "ethnicity", "", 1)%>">author ethnicity</option>
  28.             </select>
  29.             <select class="inputSubmit" id="selRace" onchange="javascript:changevalue(this);" name="selRace" style="width:150px;">
  30.                 <option value="<%=ChangeValue(Request.RawUrl.ToString(), "race", "", 1)%>">author race</option>
  31.             </select>
  32.  
AJAX SCRIPT
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2. var notWhitespace = /\S/
  3.  
  4. function cleanWhitespace(node)
  5. {
  6.     for (var x = 0; x < node.childNodes.length; x++)
  7.     {
  8.         var childNode = node.childNodes[x]
  9.         if ((childNode.nodeType == 3) && (!notWhitespace.test(childNode.nodeValue)))
  10.         {
  11.             // that is, if it's a whitespace text node
  12.             node.removeChild(node.childNodes[x])
  13.             x--
  14.         }
  15.         if (childNode.nodeType == 1)
  16.         {
  17.             // elements can have text child nodes of their own
  18.             cleanWhitespace(childNode)
  19.         }
  20.     }
  21. }
  22.  
  23.  
  24.  
  25. var http_request1 = null;
  26. var http_request2 = null;
  27. var http_request3 = null;
  28.  
  29. function GetXmlHttpObject()
  30. {
  31.     var xmlHttp = null;
  32.     if (window.XMLHttpRequest)
  33.     {
  34.         xmlHttp = new XMLHttpRequest(); // Mozilla, Safari,...
  35.         if (xmlHttp.overrideMimeType)
  36.         {
  37.             xmlHttp.overrideMimeType('text/xml');
  38.         }
  39.         else if (window.ActiveXObject)
  40.         {
  41.             try
  42.             {
  43.                 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); // IE
  44.             }
  45.             catch (e)
  46.             {
  47.                 try
  48.                 {
  49.                     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE
  50.                 }
  51.                 catch (e)
  52.                 {
  53.                     // do nothing
  54.                 }
  55.             }
  56.         }
  57.         return xmlHttp;
  58.     }
  59. }
  60.  
  61. function makeRequest(url, objectname, rootname, qs)
  62. {
  63.     if (rootname == 'nationalities')
  64.     {
  65.         http_request1 = GetXmlHttpObject();
  66.         if (http_request1 == null)
  67.         {
  68.             alert('Cannot create XMLHTTP instance');
  69.             return false;
  70.         }
  71.         else
  72.         {
  73.             http_request1.onreadystatechange = alertContents1;
  74.             http_request1.open('GET', url + qs, true);
  75.             http_request1.send(null);
  76.         }
  77.     }
  78.     if (rootname == 'ethnicities')
  79.     {
  80.         http_request2 = GetXmlHttpObject();
  81.         if (http_request2 == null)
  82.         {
  83.             alert('Cannot create XMLHTTP instance');
  84.             return false;
  85.         }
  86.         else
  87.         {
  88.             http_request2.onreadystatechange = alertContents2;
  89.             http_request2.open('GET', url + qs, true);
  90.             http_request2.send(null);
  91.         }
  92.     }
  93.     if (rootname == 'races')
  94.     {
  95.         http_request3 = GetXmlHttpObject();
  96.         if (http_request3 == null)
  97.         {
  98.             alert('Cannot create XMLHTTP instance');
  99.             return false;
  100.         }
  101.         else
  102.         {
  103.             http_request3.onreadystatechange = alertContents3;
  104.             http_request3.open('GET', url + qs, true);
  105.             http_request3.send(null);
  106.         }
  107.     }
  108. }
  109.  
  110. function alertContents1()
  111. {
  112.     if (http_request1.readyState == 4)
  113.     {
  114.         if (http_request1.status == 200)
  115.         {
  116.             var xmldoc = http_request1.responseXML;
  117.             cleanWhitespace(xmldoc);
  118.  
  119.             var root;
  120.             root = xmldoc.getElementsByTagName('nationalities').item(0);
  121.  
  122.             var arr1 = new Array(root.childNodes.length);
  123.             var arr2 = new Array(root.childNodes.length);
  124.  
  125.             for (var iNode = 0; iNode < root.childNodes.length; iNode++) 
  126.             {
  127.                 var node = root.childNodes[iNode]
  128.                 arr1[iNode] = node.childNodes[0].childNodes[0].nodeValue;
  129.                 arr2[iNode] = node.childNodes[1].childNodes[0].nodeValue;
  130.             }
  131.  
  132.             addrow('selNationality', arr1, arr2);
  133.             if (document.getElementById('selNationality').options.length < 3)
  134.             {
  135.                 document.getElementById('selNationality').style.display = "none";
  136.             }
  137.         }
  138.         else
  139.         {
  140.             alert('There was a problem with the request.');
  141.         }
  142.     }
  143. }
  144.  
  145. function alertContents2()
  146. {
  147.     if (http_request2.readyState == 4)
  148.     {
  149.         if (http_request2.status == 200)
  150.         {
  151.             var xmldoc = http_request2.responseXML;
  152.             cleanWhitespace(xmldoc);
  153.  
  154.             var root;
  155.             root = xmldoc.getElementsByTagName('ethnicities').item(0);
  156.  
  157.             var arr1 = new Array(root.childNodes.length);
  158.             var arr2 = new Array(root.childNodes.length);
  159.  
  160.             for (var iNode = 0; iNode < root.childNodes.length; iNode++) 
  161.             {
  162.                 var node = root.childNodes[iNode]
  163.                 arr1[iNode] = node.childNodes[0].childNodes[0].nodeValue;
  164.                 arr2[iNode] = node.childNodes[1].childNodes[0].nodeValue;
  165.             }
  166.  
  167.             addrow('selEthnicity', arr1, arr2);
  168.             if (document.getElementById('selEthnicity').options.length < 3)
  169.             {
  170.                 document.getElementById('selEthnicity').style.display = "none";
  171.             }
  172.         }
  173.         else
  174.         {
  175.             alert('There was a problem with the request.');
  176.         }
  177.     }
  178. }
  179.  
  180. function alertContents3()
  181. {
  182.     if (http_request3.readyState == 4)
  183.     {
  184.         if (http_request3.status == 200)
  185.         {
  186.             var xmldoc = http_request3.responseXML;
  187.             cleanWhitespace(xmldoc);
  188.  
  189.             var root;
  190.             root = xmldoc.getElementsByTagName('races').item(0);
  191.  
  192.             var arr1 = new Array(root.childNodes.length);
  193.             var arr2 = new Array(root.childNodes.length);
  194.  
  195.             for (var iNode = 0; iNode < root.childNodes.length; iNode++) 
  196.             {
  197.                 var node = root.childNodes[iNode]
  198.                 arr1[iNode] = node.childNodes[0].childNodes[0].nodeValue;
  199.                 arr2[iNode] = node.childNodes[1].childNodes[0].nodeValue;
  200.             }
  201.  
  202.             addrow('selRace', arr1, arr2);
  203.             if (document.getElementById('selRace').options.length < 3)
  204.             {
  205.                 document.getElementById('selRace').style.display = "none";
  206.             }
  207.         }
  208.         else
  209.         {
  210.             alert('There was a problem with the request.');
  211.         }
  212.     }
  213. }
  214.  
  215. function changevalue(ele)
  216. {
  217.     window.location = ele.options[ele.selectedIndex].value;
  218. }
  219.  
  220. function do_xml(scriptname, objectname, rootname, qs)
  221. {
  222.     if (rootname == "nationalities")
  223.     {
  224.         document.getElementById('selNationality').onclick = "";
  225.     }
  226.  
  227.     if (rootname == "ethnicities")
  228.     {
  229.         document.getElementById('selEthnicity').onclick = "";
  230.     }
  231.  
  232.     if (rootname == "races")
  233.     {
  234.         document.getElementById('selRace').onclick = "";
  235.     }
  236.  
  237.     makeRequest(scriptname, objectname, rootname, qs);
  238. }
  239.  
  240. function addrow(objectname, arr1, arr2)
  241. {
  242.     var dropdown = document.getElementById(objectname);
  243.  
  244.     for (r = 0; r < arr1.length; r++)
  245.     {
  246.         var txt = arr1[r];
  247.         var val = arr2[r];
  248.         var newOpt;
  249.  
  250.         if (objectname == "selNationality")
  251.         {
  252.             if (Url.decode(getQueryVariable("nationality")).replace( /\+/g, " " ) == txt)
  253.             {
  254.                 newOpt = new Option(txt, val, true, true);
  255.             }else{
  256.                 newOpt = new Option(txt, val, false, false);
  257.             }
  258.         }
  259.  
  260.         if (objectname == "selEthnicity")
  261.         {
  262.             if (Url.decode(getQueryVariable("ethnicity")).replace( /\+/g, " " ) == txt)
  263.             {
  264.                 newOpt = new Option(txt, val, true, true);
  265.             }else{
  266.                 newOpt = new Option(txt, val, false, false);
  267.             }
  268.         }
  269.  
  270.         if (objectname == "selRace")
  271.         {
  272.             if (Url.decode(getQueryVariable("race")).replace( /\+/g, " " ) == txt)
  273.             {
  274.                 newOpt = new Option(txt, val, true, true);
  275.             }else{
  276.                 newOpt = new Option(txt, val, false, false);
  277.             }
  278.         }
  279.  
  280.         dropdown.options[dropdown.options.length] = newOpt;
  281.     }
  282. }
  283.  
  284. function getQueryVariable(variable) {
  285.     var query = window.location.search.substring(1);
  286.     var vars = query.split("&");
  287.  
  288.     for (var i=0;i<vars.length;i++) {
  289.         var pair = vars[i].split("=");
  290.         if (pair[0] == variable) {
  291.             if (pair[1].toString().trim() == ""){
  292.                 return null;
  293.             }else{
  294.                 return pair[1];
  295.             }
  296.         }
  297.     }
  298. }
  299. String.prototype.trim = function() {
  300.     a = this.replace(/^\s+/, '');
  301.     return a.replace(/\s+$/, '');
  302. };
  303. </script>
  304.  
Any help is so greatly appreciated if you come to the northern virginia area I promise you a cold brew!

cheers!
- John West
Aug 20 '07 #1
4 8267
dmjpro
2,476 Top Contributor
Welcome to TSDN.
It was no need to post all these codes.
Aneway, you made a silly mistake at the first of your GetXmlHttpObjec t function.
Look there a condition set first that if(window.XMLHt tpRequest) and the whole code is under this condition.
Now for IE it is false so ur XMLHttpObject returns NULL.
Your code shud be like this....

Expand|Select|Wrap|Line Numbers
  1. if(window.XMLHttpRequest)
  2. {
  3. //For Mozilla based browser
  4. }
  5. else if(window.ActiveXObject)
  6. {
  7. //For IE browser
  8. }
  9.  
Now I think your code will work well.
Best of luck.

Kind regards,
Dmjpro.
Aug 21 '07 #2
gits
5,390 Recognized Expert Moderator Expert
heya ...

yep ;) ... simply put a } to line 38 ... small fix but great improvement ;) ... IE is not to be blamed that time (not for this problem at least), except of needing an extra-handling ... but the XMLHttpRequest was an invention of MS ... so be a little bit generous with it this time ... i know ... it is hard to be generous with that browsers exceptions all the time ;)

kind regards
Aug 21 '07 #3
sirjohnofthewest
3 New Member
Alas! theScripts community strikes again FTW!

Thank you so much for your guys' help it was definitely much appreciated :)


Cheers,
` John West
Aug 21 '07 #4
dmjpro
2,476 Top Contributor
Alas! theScripts community strikes again FTW!

Thank you so much for your guys' help it was definitely much appreciated :)


Cheers,
` John West

Hey what do u mean by FWT????
Aug 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2684
by: minjie | last post by:
Hello, I installed DB2 UDB V8.1 on a linux machine, and then deinstalled it because of some other problems. When I reinstalled it and tried to create an instance with the same name again (db2inst1), I was told the following error: "The instance that is being created or migrated is already in the instance list". I had this problem before and...
0
1993
by: andrewcw | last post by:
I am trying to set the column information - which ones I want displayed and how with the web grid control. The interface has some big differences when compared to the winform. Is this possible without having the dataset match ? I think yes... but ... here's how I approached it: ( create new DataGridColumns, add properties and then add each to...
2
13737
by: Andrew | last post by:
I am trying to set the column information - which ones I want displayed and how with the web grid control. The interface has some big differences when compared to the winform. Is this possible without having the dataset match ? I think yes... but ... here's how I approached it: ( create new DataGridColumns, add properties and then add each...
0
1127
by: Amedee Van Gasse | last post by:
I have the following code: Public Class frmMyForm Inherits System.Windows.Forms.Form Friend cnMyConnection As System.Data.OleDb.OleDbConnection Public Sub ShowMe() Me.Show() If Me.WindowState = FormWindowState.Minimized Then
18
7374
by: Sandra-24 | last post by:
Can you create an instance of a subclass using an existing instance of the base class? Such things would be impossible in some languages or very difficult in others. I wonder if this can be done in python, without copying the base class instance, which in my case is a very expensive object. Any ideas? Thanks,
1
2480
by: mussitsch | last post by:
I have one user who is running Internet Explorer version: Version 6.0.2800.1106. SP1;Q823353 I have the following code that tries to create the xmlhttp object. For some reason, it will not create for her. I thought most browsers were covered by this code. try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try {...
0
1188
by: glieux | last post by:
Is it possible to create a XMLHTTP instance on a Palm TX - OS5 ? I'm trying to use an email that requires such for attachments and such.
13
3721
by: miztaken | last post by:
Hi, My C# application have a following code to create an instance of Visual Studio. System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE. 8.0"); Object obj = System.Activator.CreateInstance(type, true); EnvDTE80.DTE2 dte8Obj = (EnvDTE80.DTE2)obj; MessageFilter.Register(); dte8Obj.MainWindow.Visible = false;
3
1301
by: jimgardener | last post by:
hi, i am a python newbie..while trying out some message passing between two object instances i came across a problem moduleA.py -------------------- import moduleB class MyClassA: def __init__(self): self.age=0 self.address=''
0
7948
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8150
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6329
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5523
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5247
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.