Results 1 to 2 of 2

Thread: AJAX - can't read XML from ASP

  1. #1
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default AJAX - can't read XML from ASP

    Hi,
    have just started learning AJAX and have come up against the following problem.

    The following code works fine when using a plain .xml file as the input, but when substituting a .asp file that produces identical output, it doesn't recognise xmlDoc as an XML document. Curiously, xmlHttp.responseText reproduces the XML perfectly. Can anyone help?

    Many thanks, Guy

    <script>
    var xmlHttp;
    function startRequest() {
    try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlHttp.onreadystatechange = handleStateChange;
    xmlHttp.open("GET", "simple.xml", true);
    xmlHttp.send(null);
    }
    catch(err) {
    alert("startRequest error: " + err.message);
    }
    }
    function handleStateChange() {
    if(xmlHttp.readyState == 4) {
    if(xmlHttp.status == 200) {
    try {
    alert(xmlHttp.getAllResponseHeaders());
    var xmlDoc = xmlHttp.responseXML;
    var myTag = xmlDoc.getElementsByTagName("item1");
    alert(myTag[0].firstChild.nodeValue);
    }
    catch(err) {
    alert("handleStateChange error: " + err.message);
    }
    }
    }
    }
    </script>

  2. #2
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorted it. I just needed to put

    <&#37;
    response.ContentType = "text/xml"
    %>

    in my asp file. Otherwise the response header is set to Content-type: "text/html" which I guess is what the problem was.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •