XMLHTTP - null is null or not an object

T

Tim Platt

I would be very grateful if someone could assist me. I am relatively
new to httpxml and xml in general. I have done a lot of research and
tried lots of examples, most of which I can get working.

I am trying to send a request to a server for some vehicle data, which
I then want to display.

I have the following code. If I set the loadXMLDoc to an XML file on
the client it works fine. There is obviously a gap in my understanding
- why can I not get this to work? Any help greatly appreciated.

<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("Microsoft.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>Model:</b>
<br><span id="A4"></span>
</p>

</body>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top