M
m_p_v_13
In Firefox (2.0.0.18) .readyState hung at 3 where .responseText has
the data but .responseXML is nul.
A school project whiched worked last year is failing now. I've
updated my browser and the LAMP server was probably updated also in
that time.
The problem is that xmlHttp.readyState gets up to 3 and then
no more state changes. It works OK in IE.
I recreated the problem using the sample program found here.
http://www.w3schools.com/php/php_ajax_responsexml.asp
I modified the php to dummy up the data to eliminate the mySQL
and added some alerts.
I suspect the XML parsing is having a problem, however the XML looks
good
when I see it in responsText using firebug.
Please, can anyone shed some light on what is wrong?
Here is the source:
---- hangon3.html ---------------------------
<html>
<head>
<script src="hangon3.js"></script>
</head>
<body>
<form>
Select a User:
<select name="users" onchange="showUser(this.value)">
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<h2><span id="firstname"></span>
<span id="lastname"></span></h2>
<span id="job"></span>
<div style="text-align: right">
<span id="age_text"></span>
<span id="age"></span>
<span id="hometown_text"></span>
<span id="hometown"></span>
</div>
</body>
</html>
---------------------------------------------
---- hangon3.php ----------------------------
<?php
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
//A date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<person>';
echo "<firstname>Michael</firstname>";
echo "<lastname>Vogt</lastname>";
echo "<age>51</age>";
echo "<hometown>Miami</hometown>";
echo "<job>Student</job>";
echo "</person>";
?>
---------------------------------------------
---- hangon3.js -----------------------------
var xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="hangon3.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
alert("before xmlHttp.send()");
xmlHttp.send(null)
alert("after xmlHttp.send()");
}
function stateChanged()
{
alert( "stateChanged readyState=" + xmlHttp.readyState );
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
alert( "processing XML " + xmlHttp.responseXML );
xmlDoc=xmlHttp.responseXML;
document.getElementById("firstname").innerHTML=
xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;
document.getElementById("lastname").innerHTML=
xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue;
document.getElementById("job").innerHTML=
xmlDoc.getElementsByTagName("job")[0].childNodes[0].nodeValue;
document.getElementById("age_text").innerHTML="Age: ";
document.getElementById("age").innerHTML=
xmlDoc.getElementsByTagName("age")[0].childNodes[0].nodeValue;
document.getElementById("hometown_text").innerHTML="<br/>From: ";
document.getElementById("hometown").innerHTML=
xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue;
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
---------------------------------------------
the data but .responseXML is nul.
A school project whiched worked last year is failing now. I've
updated my browser and the LAMP server was probably updated also in
that time.
The problem is that xmlHttp.readyState gets up to 3 and then
no more state changes. It works OK in IE.
I recreated the problem using the sample program found here.
http://www.w3schools.com/php/php_ajax_responsexml.asp
I modified the php to dummy up the data to eliminate the mySQL
and added some alerts.
I suspect the XML parsing is having a problem, however the XML looks
good
when I see it in responsText using firebug.
Please, can anyone shed some light on what is wrong?
Here is the source:
---- hangon3.html ---------------------------
<html>
<head>
<script src="hangon3.js"></script>
</head>
<body>
<form>
Select a User:
<select name="users" onchange="showUser(this.value)">
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<h2><span id="firstname"></span>
<span id="lastname"></span></h2>
<span id="job"></span>
<div style="text-align: right">
<span id="age_text"></span>
<span id="age"></span>
<span id="hometown_text"></span>
<span id="hometown"></span>
</div>
</body>
</html>
---------------------------------------------
---- hangon3.php ----------------------------
<?php
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
//A date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<person>';
echo "<firstname>Michael</firstname>";
echo "<lastname>Vogt</lastname>";
echo "<age>51</age>";
echo "<hometown>Miami</hometown>";
echo "<job>Student</job>";
echo "</person>";
?>
---------------------------------------------
---- hangon3.js -----------------------------
var xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="hangon3.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
alert("before xmlHttp.send()");
xmlHttp.send(null)
alert("after xmlHttp.send()");
}
function stateChanged()
{
alert( "stateChanged readyState=" + xmlHttp.readyState );
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
alert( "processing XML " + xmlHttp.responseXML );
xmlDoc=xmlHttp.responseXML;
document.getElementById("firstname").innerHTML=
xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;
document.getElementById("lastname").innerHTML=
xmlDoc.getElementsByTagName("lastname")[0].childNodes[0].nodeValue;
document.getElementById("job").innerHTML=
xmlDoc.getElementsByTagName("job")[0].childNodes[0].nodeValue;
document.getElementById("age_text").innerHTML="Age: ";
document.getElementById("age").innerHTML=
xmlDoc.getElementsByTagName("age")[0].childNodes[0].nodeValue;
document.getElementById("hometown_text").innerHTML="<br/>From: ";
document.getElementById("hometown").innerHTML=
xmlDoc.getElementsByTagName("hometown")[0].childNodes[0].nodeValue;
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
---------------------------------------------