...

View Full Version : AJAX XML responseXML erroring..



chris_angell
09-24-2007, 12:36 PM
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....

rwedge
09-24-2007, 05:26 PM
Try this in the asp page:
<%
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>")
%>

chris_angell
09-24-2007, 05:32 PM
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

chris_angell
09-24-2007, 06:10 PM
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

rwedge
09-27-2007, 01:50 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum