ajax javascript response

Y

Yorian

Hi,

Another problem another question (as usual). I want to retrieve data
through
ajax, within the data there is some javascript which needs to be used
(I
figured that one out using eval ()). The problem is that the script I
run
(and get from the response) needs to use the response itself.

Now after some testing I came to this:


To make things more clear, some code:

the function which handles the response:

function getPageData(http_request) {
try {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var xml = http_request.responseXML;

var script =
xml.getElementsByTagName('evalscript')[0].childNodes[1].nodeValue;
eval(script);
} else {
alert('There was a problem with the request.');
}
}
}
catch( e ) {
alert('Caught Exception: ' + e.description);
}
}

the response send to this function:
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<evalscript>
<![CDATA[
document.getElementById('extendedinfo_form').innerHTML =
xml.getElementsByTagName('output')[0].childNodes[0].nodeValue;
]]>
</evalscript>
<output>
&lt;b&gt;surf&lt;/b&gt;
</output>
</root>

Now the questions:
1: I tried to use real html tags within <output> and </output> and get
the contents using innerHTML like so:
xml.getElementsByTagName('output')[0].innerHTML;

But that will return undefined. So can anyone tell me why that doesn't
work and why I need to change the < and > to &lt; and &gt;

2: What I have got now works in Firefox but not in Internet Explorer,
in which it returns an error:
Caught Exception: object expected

Can anybody help me out?

cheers,

Yorian
 
Y

Yorian

Isn't there anybody who can help me solve this problem even if I have
to change the way everything works a little bit. (although I would love
the the bit where I don't have too make a function for every little bit
of ajax). It is just the problem in Internet Explorer that bugs me,
isn't there a way to find out what the problem is in IE? That would
help me out a lot!
 
P

pcx99

Yorian said:
Isn't there anybody who can help me solve this problem even if I have
to change the way everything works a little bit. (although I would love
the the bit where I don't have too make a function for every little bit
of ajax). It is just the problem in Internet Explorer that bugs me,
isn't there a way to find out what the problem is in IE? That would
help me out a lot!

To be fair you're working in a rather esoteric area of ajax/javascript.
There's a lot of press about ajax and xml has more hype than global
warming, but most people use responsetext instead of responsexml
because it's a lot easier to just do something like

record1~~field1~~field2~~field3``
record2~~field1~~field2~~field3``

and split('~~')/split('``') in javascript. It's easier to format on the
server end, it's easier to parse on the client end, and until you start
getting into mid-large sized corporate bureaucracies, responsexml just
isn't going to be on the radar.

That said...
1: I tried to use real html tags within <output> and </output> and get
the contents using innerHTML like so:
xml.getElementsByTagName('output')[0].innerHTML;

I believe the [0] is unnecessary in this context. [] is used to denote
dom level elements, but you're pulling the tag directly by name so there
is no index element. Try xml.getElementsByTagName('output').innerHTML;
and see if it solves your problem.

You're basically escaping the data so the data doesn't become part of
the xml record structure. Without amping <> you end up with...

<output>
<b>surf</b>
</output>

Now you have a record -- output, and a sub-record <B> so output.b = surf
instead of output=<B>surf</B> which is what you want.

Again, I have no direct experience working with xml so this is just
pulled off similar experiences working with similar elements of the DOM,
it probably won't help you but on the off chance that it might, well,
it's Christmas. Miracles happen, thought if it's either or, I'd prefer
the miracle to work on tonight's lotto ticket ;)

G'luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top