469,271 Members | 1,250 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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) {
  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 2798
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
150 100+
that is the error i got :
firstCategory.getElementsByTagName is not a function
Oct 7 '07 #3
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
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">
<script language="javascript" type="text/javascript">
function AJAX(num){
XMLObject = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
XMLObject = new XMLHttpRequest();
if (XMLObject.overrideMimeType) {
} 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;
if(XMLObject.readyState==4 && XMLObject.status==200){
var XMLFILE=XMLObject.responseXML;
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;
document.getElementById("Menu").options[i]=new Option(firstMenu.childNodes[i].firstChild.nodeValue);
function makeData(what){
return what.selectedIndex;
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<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 name="Menu" id="Menu" onchange="">
<option>- Choose -</option>
and that is my XML File:

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Menu type='Bags, Cases &amp; Straps'>
<subMenu>For Camcorders</subMenu>
<subMenu>For Cameras</subMenu>
<Menu type='Binoculars &amp; Telescopes'>
<subMenu>Binoculars &amp; Monoculars</subMenu>
<subMenu>Eyepieces &amp; Telescope Accs.</subMenu>
<subMenu>Telinoculars &amp; Telescopesescopes</subMenu>
<Menu type='Camcorder Accessories'>
<subMenu>Batteries &amp; Chargers</subMenu>
<subMenu>Blank Tapes &amp; Memory</subMenu>
<subMenu>Cables, Cords &amp; Connectors</subMenu>
<subMenu>Lenses &amp; Accessories</subMenu>
<Menu type='Camcorders'>
<subMenu>8mm, Hi8, VHS</subMenu>
<subMenu>Digital 8</subMenu>
<subMenu>Other Digital Formats</subMenu>
<Menu type='Digital Camera Accessories'>
<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 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 type='Film'>
<subMenu>Medium, Large Format</subMenu>
<subMenu>Polaroid &amp; Instant Print</subMenu>
<subMenu>Processing &amp; Other</subMenu>
<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 type='Film Cameras'>
<subMenu>35mm Point &amp; Shoot</subMenu>
<subMenu>35mm Rangefinder</subMenu>
<subMenu>35mm SLR</subMenu>
<subMenu>Cameras for Kids</subMenu>
<subMenu>Instant Print, Polaroid</subMenu>
<subMenu>Large Format</subMenu>
<subMenu>Medium Format</subMenu>
<subMenu>Parts &amp; Repair</subMenu>
<subMenu>Submini, Disc, 110</subMenu>
<subMenu>Other Film Cameras</subMenu>
<Menu type='Film Processing &amp; Darkroom'>
<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 type='Flashes &amp; Accessories'>
<subMenu>Digital Camera Flash Units</subMenu>
<subMenu>Film Camera Flash Units</subMenu>
<subMenu>Flash Accessories</subMenu>
<Menu type='Lenses &amp; Filters'>
<subMenu>Digital Camera Lenses</subMenu>
<subMenu>Film Camera Lenses</subMenu>
<subMenu>Filter Accessories</subMenu>
<subMenu>Lens Accessories</subMenu>
<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>Studio Flash/Strobe</subMenu>
<subMenu>Other Lighting &amp; Studio Items</subMenu>
<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 type='Photo Albums &amp; Archive Items'>
<subMenu>Archival &amp; Mounting Materials</subMenu>
<subMenu>Photo Albums</subMenu>
<subMenu>Other Albums &amp; Archive Items</subMenu>
<Menu type='Printers, Scanners &amp; Supplies'>
<subMenu>Photo Printers</subMenu>
<subMenu>Printing Software &amp; Supplies</subMenu>
<Menu type='Professional Video Equipment'>
<subMenu>Blank Tapes &amp; Media</subMenu>
<subMenu>Cables &amp; Wires</subMenu>
<subMenu>Editing, Post-Production</subMenu>
<subMenu>Recorders &amp; Players</subMenu>
<subMenu>Video Switchers, Routers</subMenu>
<Menu type='Projection Equipment'>
<subMenu>Other Projection Equipment</subMenu>
<Menu type='Stock Photography &amp; Footage'>
<Menu type='Tripods, Monopods'>
<subMenu>Other Tripod, Monopod Items</subMenu>
<Menu type='Vintage'>
<subMenu>Other Vintage Items</subMenu>
<Menu type='Wholesale Lots'>
<subMenu>General Accessories</subMenu>

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

Post your reply

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

Similar topics

5 posts views Thread by namemattersnot | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.