473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

work in Internet Explorer only ajax code

150 100+
I'm having problem with this code why i don't know works fine in Internet Explorer only that is my code:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. function AJAX(num){
  3.     XMLObject = false;
  4.     if (window.XMLHttpRequest) { // Mozilla, Safari,...
  5.         XMLObject = new XMLHttpRequest();
  6.         if (XMLObject.overrideMimeType) {
  7.             XMLObject.overrideMimeType('text/xml');
  8.         }
  9.     } else if (window.ActiveXObject){ // IE
  10.         try {
  11.             XMLObject = new ActiveXObject("Msxml2.XMLHTTP");
  12.         } catch (e) {
  13.                 try {
  14.                     XMLObject = new ActiveXObject("Microsoft.XMLHTTP");
  15.                 }catch (e) {
  16.  
  17.                 }
  18.             }
  19.         }
  20.     if (!XMLObject) {
  21.         alert('Cannot create XMLHTTP instance');
  22.         return false;
  23.     }
  24.     XMLObject.open("GET","XML.php");
  25.     XMLObject.onreadystatechange=function(){
  26.         if(XMLObject.readyState==4 && XMLObject.status==200){
  27.             var XMLFILE=XMLObject.responseXML;
  28.             makeList(XMLFILE,num);
  29.         }
  30.     }
  31.     XMLObject.send(null);
  32. }
  33. function makeList(XMLData,num){
  34.     var firstCategory=XMLData.documentElement.firstChild;
  35.     var AllMenus=firstCategory.getElementsByTagName("Menu");
  36.     var firstMenu=AllMenus[num];
  37.     for(i=0;i<document.getElementById("Menu").options.length;i++){
  38.         document.getElementById("Menu").options[i]= null;
  39.     }
  40.     for(i=0;i<firstMenu.childNodes.length;i++){
  41.         document.getElementById("Menu").options[i]=new Option(firstMenu.childNodes[i].firstChild.nodeValue);
  42.     }
  43. }
  44. function makeData(what){
  45.     return what.selectedIndex;
  46. }
  47. </script>
Oct 7 '07 #1
4 3058
gits
5,390 Expert Mod 4TB
hi ...

what error do you get, if one? or could you please tell what is not working?

kind regards
Oct 7 '07 #2
smartic
150 100+
that is the error i got :
firstCategory.getElementsByTagName is not a function
Oct 7 '07 #3
gits
5,390 Expert Mod 4TB
hi ...

could you post what you get from:

Expand|Select|Wrap|Line Numbers
  1. var firstCategory=XMLData.documentElement.firstChild;
may be there is a whitespace-problem in your xml-document? try to refer the first element another way ... through tagName or something like that.

kind regards
Oct 7 '07 #4
smartic
150 100+
That is my HTML page:
[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript" type="text/javascript">
function AJAX(num){
XMLObject = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
XMLObject = new XMLHttpRequest();
if (XMLObject.overrideMimeType) {
XMLObject.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject){ // IE
try {
XMLObject = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
XMLObject = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e) {

}
}
}
if (!XMLObject) {
alert('Cannot create XMLHTTP instance');
return false;
}
XMLObject.open("GET","XML.php");
XMLObject.onreadystatechange=function(){
if(XMLObject.readyState==4 && XMLObject.status==200){
var XMLFILE=XMLObject.responseXML;
makeList(XMLFILE,num);
}
}
XMLObject.send(null);
}
function makeList(XMLData,num){
var firstCategory=XMLData.documentElement.firstChild;
var AllMenus=firstCategory.getElementsByTagName("Menu" );
var firstMenu=AllMenus[num];
for(i=0;i<document.getElementById("Menu").options. length;i++){
document.getElementById("Menu").options[i]= null;
}
for(i=0;i<firstMenu.childNodes.length;i++){
document.getElementById("Menu").options[i]=new Option(firstMenu.childNodes[i].firstChild.nodeValue);
}
}
function makeData(what){
return what.selectedIndex;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="p ost" action="">
<select name="Category" id="Category" onchange="AJAX(makeData(this))">
<option>Cameras &amp; Photo</option>
<option>Consumer Electronics</option>
<option>Jewelry &amp; Watches</option>
<option>Real Estate</option>
</select>
<select name="Menu" id="Menu" onchange="">
<option>- Choose -</option>
</select>
</form>
</body>
</html>[/HTML]
and that is my XML File:

[PHP]<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("content-type:text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Commercila>
<CamerasAndPhotos>
<Menu type='Bags, Cases &amp; Straps'>
<subMenu>For Camcorders</subMenu>
<subMenu>For Cameras</subMenu>
</Menu>
<Menu type='Binoculars &amp; Telescopes'>
<subMenu>Binoculars &amp; Monoculars</subMenu>
<subMenu>Eyepieces &amp; Telescope Accs.</subMenu>
<subMenu>Telinoculars &amp; Telescopesescopes</subMenu>
</Menu>
<Menu type='Camcorder Accessories'>
<subMenu>Accessories</subMenu>
<subMenu>Batteries &amp; Chargers</subMenu>
<subMenu>Blank Tapes &amp; Memory</subMenu>
<subMenu>Cables, Cords &amp; Connectors</subMenu>
<subMenu>Lenses &amp; Accessories</subMenu>
</Menu>
<Menu type='Camcorders'>
<subMenu>8mm, Hi8, VHS</subMenu>
<subMenu>Digital 8</subMenu>
<subMenu>DVD</subMenu>
<subMenu>HDD</subMenu>
<subMenu>HDV</subMenu>
<subMenu>MicroMV</subMenu>
<subMenu>MiniDV</subMenu>
<subMenu>Other Digital Formats</subMenu>
</Menu>
<Menu type='Digital Camera Accessories'>
<subMenu>Accessories</subMenu>
<subMenu>Batteries &amp; Chargers</subMenu>
<subMenu>Cables, Cords &amp; Connectors</subMenu>
<subMenu>Digital Photo Frames</subMenu>
<subMenu>Memory Cards</subMenu>
<subMenu>Memory Card Adapters &amp; Readers</subMenu>
</Menu>
<Menu type='Digital Cameras'>
<subMenu>Point &amp; Shoot</subMenu>
<subMenu>Digital SLR</subMenu>
<subMenu>Specialty Digital Cameras</subMenu>
<subMenu>Parts &amp; Repair</subMenu>
<subMenu>Other Digital Cameras</subMenu>
</Menu>
<Menu type='Film'>
<subMenu>16MM</subMenu>
<subMenu>35MM</subMenu>
<subMenu>APS</subMenu>
<subMenu>Medium, Large Format</subMenu>
<subMenu>Polaroid &amp; Instant Print</subMenu>
<subMenu>Processing &amp; Other</subMenu>
</Menu>
<Menu type='Film Camera Accessories'>
<subMenu>Cables, Cords &amp; Connectors</subMenu>
<subMenu>Camera Body Accessories</subMenu>
<subMenu>Remotes &amp; Wireless</subMenu>
<subMenu>Other Film &amp; Movie Accessories</subMenu>
</Menu>
<Menu type='Film Cameras'>
<subMenu>35mm Point &amp; Shoot</subMenu>
<subMenu>35mm Rangefinder</subMenu>
<subMenu>35mm SLR</subMenu>
<subMenu>APS</subMenu>
<subMenu>Cameras for Kids</subMenu>
<subMenu>Disposable</subMenu>
<subMenu>Instant Print, Polaroid</subMenu>
<subMenu>Large Format</subMenu>
<subMenu>Medium Format</subMenu>
<subMenu>Movie</subMenu>
<subMenu>Parts &amp; Repair</subMenu>
<subMenu>Submini, Disc, 110</subMenu>
<subMenu>Underwater</subMenu>
<subMenu>Other Film Cameras</subMenu>
</Menu>
<Menu type='Film Processing &amp; Darkroom'>
<subMenu>Chemistry</subMenu>
<subMenu>Enlargement Equip. &amp; Supplies</subMenu>
<subMenu>Finishing Equipment</subMenu>
<subMenu>Hardware, Lighting &amp; Setup</subMenu>
<subMenu>Loupes &amp; Magnifiers</subMenu>
<subMenu>Photographic Paper</subMenu>
<subMenu>Processing Equipment</subMenu>
<subMenu>Other Darkroom Equipment</subMenu>
</Menu>
<Menu type='Flashes &amp; Accessories'>
<subMenu>Digital Camera Flash Units</subMenu>
<subMenu>Film Camera Flash Units</subMenu>
<subMenu>Flash Accessories</subMenu>
</Menu>
<Menu type='Lenses &amp; Filters'>
<subMenu>Digital Camera Lenses</subMenu>
<subMenu>Film Camera Lenses</subMenu>
<subMenu>Filter Accessories</subMenu>
<subMenu>Filters</subMenu>
<subMenu>Lens Accessories</subMenu>
</Menu>
<Menu type='Lighting &amp; Studio Equipment'>
<subMenu>Background Material &amp; Equip</subMenu>
<subMenu>Booms, Stands &amp; Supports</subMenu>
<subMenu>Continuous Lighting</subMenu>
<subMenu>Light Controls &amp; Modifiers</subMenu>
<subMenu>Light Meters</subMenu>
<subMenu>Portable Flash/Strobe</subMenu>
<subMenu>Props &amp; Stage Equipment</subMenu>
<subMenu>Slaves</subMenu>
<subMenu>Studio Flash/Strobe</subMenu>
<subMenu>Other Lighting &amp; Studio Items</subMenu>
</Menu>
<Menu type='Manuals, Guides &amp; Books'>
<subMenu>How-To, Guides &amp; Techniques</subMenu>
<subMenu>Camera Manuals</subMenu>
<subMenu>CheatSheets for Cameras</subMenu>
<subMenu>Lens Manuals</subMenu>
<subMenu>Other Manuals, Guides &amp; Books</subMenu>
</Menu>
<Menu type='Photo Albums &amp; Archive Items'>
<subMenu>Archival &amp; Mounting Materials</subMenu>
<subMenu>Photo Albums</subMenu>
<subMenu>Other Albums &amp; Archive Items</subMenu>
</Menu>
<Menu type='Printers, Scanners &amp; Supplies'>
<subMenu>Photo Printers</subMenu>
<subMenu>Printing Software &amp; Supplies</subMenu>
<subMenu>Scanners</subMenu>
</Menu>
<Menu type='Professional Video Equipment'>
<subMenu>Blank Tapes &amp; Media</subMenu>
<subMenu>Cables &amp; Wires</subMenu>
<subMenu>Cameras</subMenu>
<subMenu>Editing, Post-Production</subMenu>
<subMenu>Manuals</subMenu>
<subMenu>Monitors</subMenu>
<subMenu>Recorders &amp; Players</subMenu>
<subMenu>Video Switchers, Routers</subMenu>
<subMenu>Other</subMenu>
</Menu>
<Menu type='Projection Equipment'>
<subMenu>Accessories</subMenu>
<subMenu>Projectors</subMenu>
<subMenu>Screens</subMenu>
<subMenu>Other Projection Equipment</subMenu>
</Menu>
<Menu type='Stock Photography &amp; Footage'>
</Menu>
<Menu type='Tripods, Monopods'>
<subMenu>Accessories</subMenu>
<subMenu>Monopods</subMenu>
<subMenu>Tripods</subMenu>
<subMenu>Other Tripod, Monopod Items</subMenu>
</Menu>
<Menu type='Vintage'>
<subMenu>Accessories</subMenu>
<subMenu>Cameras</subMenu>
<subMenu>Projectors</subMenu>
<subMenu>Other Vintage Items</subMenu>
</Menu>
<Menu type='Wholesale Lots'>
<subMenu>Cameras</subMenu>
<subMenu>General Accessories</subMenu>
<subMenu>Vintage</subMenu>
<subMenu>Other</subMenu>
</Menu>
</CamerasAndPhotos>
</Commercila>";
[/PHP]

Please try to test my code and see the error
Oct 7 '07 #5

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

Similar topics

21
by: Joe Attardi | last post by:
Hey all! I was reading over at the IE Blog the other day http://http://blogs.msdn.com/ie/] and read some interesting, and encouraging news. According to Sunava Dutta, an IE Program Manager,...
5
by: namemattersnot | last post by:
I have a SAJAX login authentication script that, if the the correct password is provided, returns "history.go(0)" to the page and I then use "eval()" on the returned data to refresh it. If the...
1
by: mubarak basha | last post by:
hi, i wrote the following coding.......... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Getting...
8
by: jd2007 | last post by:
Why the Ajax code below in ajax.js is causing my form not to work ? ajax.js: var a=0; var b=0; var c=0; var d=0; var e=0; var f=0;
7
by: raknin | last post by:
I'm using AJAX on my website, but internet explorer does not seem to actually be refreshing the data I retrieve via AJAX when I refresh the page. For example, I have a button that when pressed uses...
3
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why is my AJAX page not updated properly when using an HTTP GET request in Internet Explorer?...
29
by: zalek | last post by:
I am writing application with Ajax in sync mode - xmlHttp.open("GET", url, false). I noticed that in FireFox handler doesn't starts. It starts when I use xmlHttp.open("GET", url,true). I need to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.