472,810 Members | 4,146 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Not understanding XMLHTTP state: help?

I am experimenting with XMLHTTP in a personal website. If I can understand it I would like to use it in a SVG application at work. But I don't get what's going on with my code, especially after reading the posts on this and other fora.

I create an object using "xmlhttp = new XMLHttpRequest();", no problem. Then I have this script:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function getContent(file){
  3.     if(file==""){ return; }
  4.     xmlhttp.onReadyStateChange=stateChange();
  5.     xmlhttp.open("GET",file,true);  //async mode!
  6.     xmlhttp.send(null);
  7. }//end function getComments
  8.  
  9. function stateChange(){
  10.     alert("state:"+xmlhttp.readyState);
  11.     if (xmlhttp.readyState==4){  // the response is complete
  12.      . . . 
  13.      var itm = xmlhttp.responseXML;
  14.      var text=itm.getElementsByTagName("content")[0].xml;
  15.      document.getElementById('xmlcontent').innerHTML=text; 
  16.      . . .
  17.  
  18.  
Then in the body of the page I have this list:

Expand|Select|Wrap|Line Numbers
  1. <form id="nulfrm" action="thispage.htm">
  2.     <select name="past_comments" size="3" onchange="getContent(this.options[this.selectedIndex].value);">
  3.         <option value="" selected>-- Select a topic from  below --</option>
  4.         <option value="test1.xml" >Test</option>
  5.         <option value="test2.xml">Other test</option>
  6.     </select>
  7. </form>
  8. <div id="xmlcontent"></div>
Problem is when I run the page, it loads and no alert shows--as expected. Then I click on a list option and I get the alert message "state:0". When I close the alert nothing else happens. I can wait all day, no other messages appear. But if I then click on the other list item I get "state:4" and the message loads into the page like I wanted it to in the first place.

I think it must be an XMLHTTP issue since I am expecting more alerts than appear. But I am prepared to be wrong. Any help is appreciated.
Aug 30 '07 #1
7 2088
dmjpro
2,476 2GB
I am experimenting with XMLHTTP in a personal website. If I can understand it I would like to use it in a SVG application at work. But I don't get what's going on with my code, especially after reading the posts on this and other fora.

I create an object using "xmlhttp = new XMLHttpRequest();", no problem. Then I have this script:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function getContent(file){
  3.     if(file==""){ return; }
  4.     xmlhttp.onReadyStateChange=stateChange();
  5.     xmlhttp.open("GET",file,true);  //async mode!
  6.     xmlhttp.send(null);
  7. }//end function getComments
  8.  
  9. function stateChange(){
  10.     alert("state:"+xmlhttp.readyState);
  11.     if (xmlhttp.readyState==4){  // the response is complete
  12.      . . . 
  13.      var itm = xmlhttp.responseXML;
  14.      var text=itm.getElementsByTagName("content")[0].xml;
  15.      document.getElementById('xmlcontent').innerHTML=text; 
  16.      . . .
  17.  
  18.  
Then in the body of the page I have this list:

Expand|Select|Wrap|Line Numbers
  1. <form id="nulfrm" action="thispage.htm">
  2.     <select name="past_comments" size="3" onchange="getContent(this.options[this.selectedIndex].value);">
  3.         <option value="" selected>-- Select a topic from  below --</option>
  4.         <option value="test1.xml" >Test</option>
  5.         <option value="test2.xml">Other test</option>
  6.     </select>
  7. </form>
  8. <div id="xmlcontent"></div>
Problem is when I run the page, it loads and no alert shows--as expected. Then I click on a list option and I get the alert message "state:0". When I close the alert nothing else happens. I can wait all day, no other messages appear. But if I then click on the other list item I get "state:4" and the message loads into the page like I wanted it to in the first place.

I think it must be an XMLHTTP issue since I am expecting more alerts than appear. But I am prepared to be wrong. Any help is appreciated.
Welcome to TSDN
This is the error in this line.
Expand|Select|Wrap|Line Numbers
  1. xmlhttp.onReadyStateChange=stateChange();   //This is wrong.
  2. xmlhttp.onReadyStateChange=stateChange;    //This one is right.
  3.  
Best of luck with your try.
Kind regards,
Dmjpro.
Aug 30 '07 #2
Welcome to TSDN
This is the error in this line.
Expand|Select|Wrap|Line Numbers
  1. xmlhttp.onReadyStateChange=stateChange();   //This is wrong.
  2. xmlhttp.onReadyStateChange=stateChange;    //This one is right.
  3.  
Best of luck with your try.
Kind regards,
Dmjpro.
Very kind of you to reply. However, if I make the change you suggest, then nothing at all happens: no alerts, no text, nothing.

Any other suggestions?
Aug 30 '07 #3
acoder
16,027 Expert Mod 8TB
Very kind of you to reply. However, if I make the change you suggest, then nothing at all happens: no alerts, no text, nothing.

Any other suggestions?
Javascript is case-sensitive. Get rid of the caps:
Expand|Select|Wrap|Line Numbers
  1. xmlhttp.onreadystatechange=...
Aug 30 '07 #4
Javascript is case-sensitive. Get rid of the caps:
Expand|Select|Wrap|Line Numbers
  1. xmlhttp.onreadystatechange=...
Brilliant 'acoder' and thanks. Case has never been a problem for me before, but your suggestion works perfectly.
Aug 30 '07 #5
dmjpro
2,476 2GB
Very kind of you to reply. However, if I make the change you suggest, then nothing at all happens: no alerts, no text, nothing.

Any other suggestions?
Hello Acoder really your eye is so perfect.
Really it's impressive.
I never gave attention to that line.

Anyway, Really you are very impressive.

Kind regards,
Dmjpro.
Aug 30 '07 #6
acoder
16,027 Expert Mod 8TB
Brilliant 'acoder' and thanks. Case has never been a problem for me before, but your suggestion works perfectly.
No problem, you're welcome. Glad you got it working.

The reason for the strange behaviour earlier was that you were setting the result of calling the function to onReadyStateChange rather than the function itself. That's why you saw the alerts only once.
Aug 30 '07 #7
pbmods
5,821 Expert 4TB
Heya, Dan.

Have a look at this article.
Aug 30 '07 #8

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

Similar topics

3
by: Mark | last post by:
Hi all i was just wondering if you help. I have to send a cgi request to a company using xmlhttp request. They reply back with a line of info but when you view the internet explorer source code...
4
by: parksch2 | last post by:
When I execute the following example code from my local test environment: var xmlhttp.open("HEAD", "http://www.google.com",true); xmlhttp.onreadystatechange=function() { if...
7
by: Fabri | last post by:
I'm trying to develop a way to include static files in htm pages with javascript. I'm trying to use XMLHTTP object this way: ...
6
by: Vanessa | last post by:
I have a question regarding async mode for calling Microsoft.XMLHTTP object. Microsoft.XMLHTTP hangs the IE once in a while suddenly, but it will work again after half an hour or so without doing...
4
by: mirandacascade | last post by:
O/S : Win2K vsn of Python: 2.4 Hoping to find information that provide information about error messages being encountered. Pythonwin session: Traceback (most recent call last): File...
13
by: yawnmoth | last post by:
<http://www.quirksmode.org/book/printable/xmlhttp.txtshows two alternatives to Microsoft.XMLHTTP - Msxml2.XMLHTTP and Msxml3.XMLHTTP. If my understanding is correct, the different numbers refer to...
1
by: wkerplunk | last post by:
Below is what I have build with several different languages. It works great but I need help, I am stuck. When you click on an item in the dropdown autocomplete div it does a mousedown function...
14
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
I've been searching everywhere online to find an alternative method besides using Microsoft.XMLHTTP (as it freezes the server up alot!!) but with no luck at all. I am using server side ASP, and...
3
by: Andrewh | last post by:
Hi, I am having a bit of a problem with using xmlhttp. The code of the javascript file is shown below used in Windows XP. var xmlhttp = null; function SetURLDiv(url) { if...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.