Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-24-2007, 12:36 PM   PM User | #1
chris_angell
Regular Coder

 
Join Date: Jul 2002
Location: Brighton, UK
Posts: 282
Thanks: 1
Thanked 0 Times in 0 Posts
chris_angell is an unknown quantity at this point
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>
chris_angell is offline   Reply With Quote
Old 09-24-2007, 05:26 PM   PM User | #2
rwedge
Regular Coder

 
Join Date: Feb 2005
Posts: 679
Thanks: 0
Thanked 16 Times in 15 Posts
rwedge is on a distinguished road
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>")
%>
rwedge is offline   Reply With Quote
Old 09-24-2007, 05:32 PM   PM User | #3
chris_angell
Regular Coder

 
Join Date: Jul 2002
Location: Brighton, UK
Posts: 282
Thanks: 1
Thanked 0 Times in 0 Posts
chris_angell is an unknown quantity at this point
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>
chris_angell is offline   Reply With Quote
Old 09-24-2007, 06:10 PM   PM User | #4
chris_angell
Regular Coder

 
Join Date: Jul 2002
Location: Brighton, UK
Posts: 282
Thanks: 1
Thanked 0 Times in 0 Posts
chris_angell is an unknown quantity at this point
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>
chris_angell is offline   Reply With Quote
Old 09-27-2007, 01:50 AM   PM User | #5
rwedge
Regular Coder

 
Join Date: Feb 2005
Posts: 679
Thanks: 0
Thanked 16 Times in 15 Posts
rwedge is on a distinguished road
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.


Quote:
... 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.

Quote:
at the mo it goes to different .asp pages for results...
Sounds like a good fall back for impaired browsers.
rwedge is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:02 PM.


Advertisement
Log in to turn off these ads.