www.webdeveloper.com
Results 1 to 2 of 2

Thread: responseXML not working

  1. #1
    Join Date
    Apr 2012
    Posts
    1

    responseXML not working

    Hi guys,

    I've been stuck on this problem now for 2 days. It seems to be a common problem from searching on forums, but none of the suggestions has worked for me.

    I am requesting a document - fakeresponse.xml, but it is not returned in the responseXML - instead it is returned in responseText.

    Here is my xml (i have used an online validator - it is fine):

    [code]
    <?xml version="1.0"?>
    <markers>
    <marker address="50 Kent Street" lat="-33.7670673" lng="150.9679327"/>
    <marker address="27 Acland Street" lat="-33.5621071" lng="149.8561493"/>
    <marker address="19 Riley Street" lat="-33.8534749" lng="142.1672888"/>
    </markers>

    [code]

    and in javascript:

    [CODE]

    var xmlhttp=false;
    var xmldoc;

    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    try {
    xmlhttp = new XMLHttpRequest();
    } catch (e) {
    xmlhttp=false;
    }
    }
    if (!xmlhttp && window.createRequest) {
    try {
    xmlhttp = window.createRequest();
    } catch (e) {
    xmlhttp=false;
    }
    }



    function getMarkers()
    {
    xmlhttp.open("GET", "fakeresponse.xml", false);
    xmlHttp.setRequestHeader("Content-Type", "text/xml");
    xmlhttp.overrideMimeType('text/xml');

    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState==4)
    {
    xmldoc = xmlhttp.responseXML;
    //xmldoc = xmlhttp.responseText;

    alert(xmldoc); // This will not execute for responseXML, but will for responseText

    var xarray = xmldoc.documentElement.childNodes;
    alert(xarray[i]);
    }
    }

    xmlhttp.send(null);
    }

    [CODE]


    Can anybody please spot what I am missing? Can jquery offer a better solution?

  2. #2
    Join Date
    Jul 2010
    Posts
    66
    Your problem was stated a couple of months ago, and I imagine you might have solved it.

    When you validated it, you basically just downloaded it to FF client from your server, right? If it were not valid, FF automatically reports parsing error.

    Can you check the HTTP response headers from your server, make sure they are sending "Content-Type: text/xml" and nothing other?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles