Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Newbie to XML - problem using xmlhttp Newbie to XML - problem using xmlhttpTo: NULL Date: 6/4/2007 6:39:00 AM
Until now I have not had any reason to learn about XML. I have spent
quite a few hours playing with examples and reading group discussions
like these - with a certain amount of success. However, I have a
specific task to accomplish, and so far I have fallen at the last
hurdle.
I want to display the following 'feed' from an external server on our
clients:
http://www.q3.hpi.co.uk/servlet/HpiGate1_0?forward=YES&efxid=0502863&password=testing&initials=tp&function=SEARCH&vrm=V110ABE&XML=YES&product=HPI11&deviceType=XM
I believe this generates data in an xml format. I assume that using
xmlhttp is the correct protocol to use (if I'm wrong please tell me).
I have copied the following code from http://www.w3schools.com:
<html>
<head>
<script type="text/javascript">
var xmlhttp
function loadXMLDoc(url)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("msxml2.XMLHTTP")
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=onResponse;
xmlhttp.open("GET",url,true);
xmlhttp.setRequestHeader("Content-Type","text/xml")
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.")
}
}
function checkReadyState(obj)
{
if(obj.readyState == 4)
{
if(obj.status == 200)
{
return true;
}
else
{
alert("Problem retrieving XML data");
}
}
}
function onResponse()
{
if(checkReadyState(xmlhttp))
{
document.getElementById('A1').innerHTML=xmlhttp.status;
document.getElementById('A2').innerHTML=xmlhttp.statustext;
document.getElementById('A3').innerHTML=xmlhttp.responsetext;
var response = xmlhttp.responseXML.documentElement;
document.getElementById('A4').innerHTML=response.getElementsByTagName("Model")
[0].firstChild.data;
}
}
</script>
</head>
<body onLoad="loadXMLDoc('http://www.q3.hpi.co.uk/servlet/HpiGate1_0?
forward=YES&efxid=0502863&password=testing&initials=tp&function=SEARCH&vrm=V110ABE&XML=YES&product=HPI11&deviceType=XM');">
<p><b>status:</b>
<span id="A1"></span>
</p>
<p><b>status text:</b>
<span id="A2"></span>
</p>
<p><b>response:</b>
<span id="A3"></span>
</p>
<p><b>response:</b>
<br><span id="A4"></span>
</p>
</body>
</html>
This appears to work fine for the status and reponsetext but I get an
error message for the responsexml - the error messages says the
elementbytagname is null.
However, if I manually save the xml file to disc and then replace the
server URL (in loadXMLDoc) with the name of the xml file it displays
the data i.e I don't get an error message.
What am I doing wrong here? I clearly don't really understand the use
of xmlhttp .
Any assistance would be gratefully received.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
