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:
[CODE=javascript]
function getContent(file ){
if(file==""){ return; }
xmlhttp.onReady StateChange=sta teChange();
xmlhttp.open("G ET",file,true ); //async mode!
xmlhttp.send(nu ll);
}//end function getComments
function stateChange(){
alert("state:"+ xmlhttp.readySt ate);
if (xmlhttp.readyS tate==4){ // the response is complete
. . .
var itm = xmlhttp.respons eXML;
var text=itm.getEle mentsByTagName( "content")[0].xml;
document.getEle mentById('xmlco ntent').innerHT ML=text;
. . .
[/CODE]
Then in the body of the page I have this list:
[CODE=html]<form id="nulfrm" action="thispag e.htm">
<select name="past_comm ents" size="3" onchange="getCo ntent(this.opti ons[this.selectedIn dex].value);">
<option value="" selected>-- Select a topic from below --</option>
<option value="test1.xm l" >Test</option>
<option value="test2.xm l">Other test</option>
</select>
</form>
<div id="xmlcontent" ></div>[/CODE]
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.
I create an object using "xmlhttp = new XMLHttpRequest( );", no problem. Then I have this script:
[CODE=javascript]
function getContent(file ){
if(file==""){ return; }
xmlhttp.onReady StateChange=sta teChange();
xmlhttp.open("G ET",file,true ); //async mode!
xmlhttp.send(nu ll);
}//end function getComments
function stateChange(){
alert("state:"+ xmlhttp.readySt ate);
if (xmlhttp.readyS tate==4){ // the response is complete
. . .
var itm = xmlhttp.respons eXML;
var text=itm.getEle mentsByTagName( "content")[0].xml;
document.getEle mentById('xmlco ntent').innerHT ML=text;
. . .
[/CODE]
Then in the body of the page I have this list:
[CODE=html]<form id="nulfrm" action="thispag e.htm">
<select name="past_comm ents" size="3" onchange="getCo ntent(this.opti ons[this.selectedIn dex].value);">
<option value="" selected>-- Select a topic from below --</option>
<option value="test1.xm l" >Test</option>
<option value="test2.xm l">Other test</option>
</select>
</form>
<div id="xmlcontent" ></div>[/CODE]
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.
Comment