Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts

    AJAX XML responseXML erroring..

    Hello I am trying to talk to an ASP page that is writing XML that has seperate values so when the info is returned to my htm page it places the content on different ID areas on my page.. but it keeps erroring on trying to get the XML value and responseXML ??

    any ideas why.. my code is below... i have been trying for ages to make it work.. but nothing

    <script>

    var req;
    var which;

    function retrieveURL(url) {
    if (url != "") {
    if (window.XMLHttpRequest) { // Non-IE browsers
    req = new XMLHttpRequest();
    req.onreadystatechange = processStateChange;
    try {
    req.open("GET", url, true);
    } catch (e) {
    alert(e);
    }
    req.send(null);
    } else if (window.ActiveXObject) { // IE
    req = new ActiveXObject("Microsoft.XMLHTTP");
    if (req) {
    req.onreadystatechange = processStateChange;
    req.open("GET", url, true);
    req.send();
    }
    }
    }
    }

    function processStateChange() {
    if (req.readyState == 4) { // Complete
    if (req.status == 200) { // OK response
    xml = req.responseXML;

    document.getElementById("Data1").innerHTML=
    xml.getElementsByTagName("compname")[0].childNodes[0].nodeValue;

    document.getElementById("Data2").innerHTML=
    xml.getElementsByTagName("address")[0].childNodes[0].nodeValue;


    } else {
    alert("Problem: " + req.statusText);
    }
    }
    }

    </script>
    <body>
    <a href="javascript:retrieveURL('show.asp')">test</a>
    <span id="Data1"></span>
    <span id="Data2"></span>
    </body>
    </html>


    HERE IS MY SHOW.ASP PAGE IT IS LINKING TO ??

    <%
    response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
    response.write("<company>")
    response.write("<compname>fdfdfd</compname>")
    response.write("<contname>dfdf</contname>")
    response.write("<address>dfdf</address>")
    response.write("<city>dfdf</city>")
    response.write("<country>fdfdf</country>")
    response.write("</company>")

    %>


    MANY THANKS CHRIS....
    <marquee>thanks</marquee>

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Try this in the asp page:
    Code:
    <%
    response.write("<rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/'>")
    response.write("<company>")
    response.write("<compname>fdfdfd</compname>")
    response.write("<contname>dfdf</contname>")
    response.write("<address>dfdf</address>")
    response.write("<city>dfdf</city>")
    response.write("<country>fdfdf</country>")
    response.write("</company>")
    response.write("</rss>")
    %>

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts
    cheers for the response... I have managed to work it out.. i needed to add contenttype = text/xml and that was it !!! i spent about an hour trying to work out that problem...

    cheers chris
    <marquee>thanks</marquee>

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Brighton, UK
    Posts
    282
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hello... I have now given up using responseXML ,, i had got it to work.. but it errored my page and seemed slow ?? so I have now decided to use xmlHttp.responseText but the problem I have now is setting the results to two different elements on my page ???

    i can send the url page to the one i need but on the xmlHttp.readyState==4 how can i run something here to determine where to place the return info ??

    at the mo it goes to different .asp pages for results...

    has anyone have any ideas on how i could break the return values into two seperate divs or spans ??

    cheers chris
    <marquee>thanks</marquee>

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Quote Originally Posted by chris_angell View Post
    but it errored my page and seemed slow ?? so I have now decided to use xmlHttp.responseText
    What kind of error?
    Time wise, I do not think there would be a noticeable difference in either method. responseXML returns XML, responseText returns a string.


    ... can send the url page to the one i need but on the xmlHttp.readyState==4 how can i run something here to determine where to place the return info ??
    has anyone have any ideas on how i could break the return values into two seperate divs or spans ??
    Parse the data from the response client side and create or target the elements you need to display it or parse server side, apply the HTML and hand it off to the response.

    at the mo it goes to different .asp pages for results...
    Sounds like a good fall back for impaired browsers.


  •  

    Posting Permissions

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