XMLHTTP - null is null or not an object

Discussion in 'Javascript' started by Tim Platt, Jun 4, 2007.

  1. Tim Platt

    Tim Platt Guest

    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>
    Tim Platt, Jun 4, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. magister pips
    Replies:
    1
    Views:
    1,153
    =?Utf-8?B?TmF0aGFuaWVsIEdyZWVuZQ==?=
    Aug 24, 2007
  2. magister pips
    Replies:
    1
    Views:
    287
    John Saunders [MVP]
    Aug 24, 2007
  3. magister pips
    Replies:
    2
    Views:
    286
    Bob Barrows [MVP]
    Aug 24, 2007
  4. RK
    Replies:
    5
    Views:
    927
    Jim Ley
    Aug 8, 2004
  5. yawnmoth

    Msxml*.XMLHTTP vs. Microsoft.XMLHTTP

    yawnmoth, Nov 7, 2006, in forum: Javascript
    Replies:
    11
    Views:
    370
    Matt Kruse
    Nov 9, 2006
Loading...

Share This Page