473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

ajax javascript response

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').inner HTML =
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 <outputand </outputand 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

Dec 11 '06 #1
2 2179
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!
Yorian wrote:
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').inner HTML =
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 <outputand </outputand 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
Dec 12 '06 #2
Yorian wrote:
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 <outputand </outputand 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.
>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;
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 <Bso output.b = surf
instead of output=<B>surf</Bwhich 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.

--
http://www.hunlock.com -- Musings in Javascript, CSS.
$FA
Dec 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole...
10
by: trpost | last post by:
I am using ajax / php where I am looking up some info from the database and populating a select list dynamically, however I am running into some sort of size limitation with the ajax.response...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
5
by: pbd22 | last post by:
Hi. I am having a hard time figuring this one out... I have a sign in page. in my sign in logic, the successful login uses forms authentication and assigns an HttpCookie for the site-wide...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
10
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario -------------...
1
by: shaunwo | last post by:
I'm an AJAX / DOM Novice (at best) and trying to figure out how to write the value to a couple input fields. I don't remember exactly where I got the ajax.js file I'm using from (went to the website...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.