473,385 Members | 1,925 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,385 software developers and data experts.

Return xmlhttprequest - variable not defined?

150 100+
i'm having problem with returning the xml object that is my code:

Expand|Select|Wrap|Line Numbers
  1. function AJAX(){
  2.     XMLObject = false;
  3.     if (window.XMLHttpRequest) { // Mozilla, Safari,...
  4.         XMLObject = new XMLHttpRequest();
  5.         if (XMLObject.overrideMimeType) {
  6.             XMLObject.overrideMimeType('text/xml');
  7.         }
  8.     } else if (window.ActiveXObject){ // IE
  9.         try {
  10.             XMLObject = new ActiveXObject("Msxml2.XMLHTTP");
  11.         } catch (e) {
  12.                 try {
  13.                     XMLObject = new ActiveXObject("Microsoft.XMLHTTP");
  14.                 }catch (e) {
  15.  
  16.                 }
  17.             }
  18.         }
  19.     if (!XMLObject) {
  20.         alert('Cannot create XMLHTTP instance');
  21.         return false;
  22.     }
  23.     XMLObject.open("GET","XML.php",true);
  24.     XMLObject.onreadystatechange=function(){
  25.         if(XMLObject.readyState==4 && XMLObject.status==200){
  26.             var XMLFILE=XMLObject.responseXML;
  27.         }
  28.     }
  29.     XMLObject.send(null);
  30.     return(XMLFILE);
  31. }
to use it in another function how can i do that ex:

Expand|Select|Wrap|Line Numbers
  1. makeList(AJAX(),makeSelection(this))
Oct 8 '07 #1
7 4502
r035198x
13,262 8TB
i'm having problem with returning the xml object that is my code:

Expand|Select|Wrap|Line Numbers
  1. function AJAX(){
  2.     XMLObject = false;
  3.     if (window.XMLHttpRequest) { // Mozilla, Safari,...
  4.         XMLObject = new XMLHttpRequest();
  5.         if (XMLObject.overrideMimeType) {
  6.             XMLObject.overrideMimeType('text/xml');
  7.         }
  8.     } else if (window.ActiveXObject){ // IE
  9.         try {
  10.             XMLObject = new ActiveXObject("Msxml2.XMLHTTP");
  11.         } catch (e) {
  12.                 try {
  13.                     XMLObject = new ActiveXObject("Microsoft.XMLHTTP");
  14.                 }catch (e) {
  15.  
  16.                 }
  17.             }
  18.         }
  19.     if (!XMLObject) {
  20.         alert('Cannot create XMLHTTP instance');
  21.         return false;
  22.     }
  23.     XMLObject.open("GET","XML.php",true);
  24.     XMLObject.onreadystatechange=function(){
  25.         if(XMLObject.readyState==4 && XMLObject.status==200){
  26.             var XMLFILE=XMLObject.responseXML;
  27.         }
  28.     }
  29.     XMLObject.send(null);
  30.     return(XMLFILE);
  31. }
to use it in another function how can i do that ex:

Expand|Select|Wrap|Line Numbers
  1. makeList(AJAX(),makeSelection(this))
And where is the problem then? Does it give you an error?
Oct 8 '07 #2
smartic
150 100+
yes it give me error XMLFILE is not defined;
Oct 8 '07 #3
r035198x
13,262 8TB
yes it give me error XMLFILE is not defined;
You declared that inside the if statement and so its scope is inside that statement only.
Oct 8 '07 #4
smartic
150 100+
but it give me another error (XMLData has no properties) in onther function when i define XMLFILE in the if statment:

Expand|Select|Wrap|Line Numbers
  1. function makeList(XMLData,num){
  2.     var Category=XMLData.documentElement.childNodes[num];
  3.     var AllMenus=Category.getElementsByTagName("Menu");
  4.     var ListOptions=document.getElementById("Menu");
  5.     var subListOptions=document.getElementById("subMenu");
  6.     //to remove extra options
  7.     ListOptions.options.length = 0
  8.     subListOptions.options.length = 0
  9.     for(i=0;i<AllMenus.length;i++){
  10.         ListOptions.options[i]=new Option(AllMenus[i].getAttribute("type"));
  11.     }    
  12. }
Oct 8 '07 #5
r035198x
13,262 8TB
But your AJAX function will not run correctly. Declare that object at the start of the method then
Oct 8 '07 #6
smartic
150 100+
can you please declare it more i don't understand
Oct 8 '07 #7
pbmods
5,821 Expert 4TB
Heya, smartic.

Have a look at this article.
Oct 9 '07 #8

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

Similar topics

22
by: googlegroups | last post by:
I am playing with the XMLHTTPRequest method to perform client/server transactions. I have it set up right now so that when readyState is 4, it takes the XML and processes it. This works great until...
5
by: willie | last post by:
hi dear committee here, Recently I am trying to writing a widget with will request a gif file from the server. I have done most of the work and the server now is sending back the gif file with the...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
20
by: chris.schwalm | last post by:
This is part II of this <a...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
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,...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
1
by: Charlie | last post by:
I am trying to make an XMLHttpRequest which violates the default "same- origin"policy in Firefox. I checked the archives and found a method that should work but it does not. Below is the test code...
5
by: HugeBob | last post by:
Hi All, I've got a question about Asynchronous vs Synchronous mode with the XMLHttpRequest object. What are the ramifications of using one mode vs the other? If the script uses Asynchronous...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.