By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 2,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

Eval multiple lines of ajax response

P: 6
Hey all
Ive ran into a bit of a problem when trying to parse multiple lines of javascript whitch are returned from an ajax request.

On the main page where the request orginates, i have a [HTML]<div id="top_left" />[/HTML]

I peform my ajax requests by using prototype as such:
Expand|Select|Wrap|Line Numbers
  1. function sendData(url, pars) {
  2. var myAjax = new Ajax.Request ( url, {method: 'get', parameters: pars, onLoading: showLoading, evalJS: true} );
  3. }
Ive set up a test, where the php script that generates the response returns:
Expand|Select|Wrap|Line Numbers
  1. $('top_left').innerHTML = 'test';
  2. alert("test");
And this seems to work fine (text is shown, and alert alerts)

However when i try and send back the following nothing at all happens:
Expand|Select|Wrap|Line Numbers
  1. $('top_left').innerHTML= '<h1>Heading</h1><span title="title text">Welcome</span><ul><li id="search">Search here</li><li id="view">View here</li>';
  2. new Draggable("search", {ghosting:true, revert:true});
  3. new Draggable("view", {ghosting;true, revert: true} );
Im compleatly baffled, ive tried escaping every quote, writing it as a lot of innerHTML writes, by appendingChild, returning the javascript to iterate though an array of the text i want displayed and write it to top_left, but Nothing seems to work.

Im unsure if theres something crucial i'm missing, or something.

If anyone could point me in the right direction that would be awsome, as im stuck (for once google hasent solved it)

Also, does anyone have a good firefox extension or know of a tool for validating ajax javascript returns?

Thanks in advance
Feb 4 '08 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
Welcome to TSDN!

There's a semi-colon between ghosting and true in the third line.

A good tool is Firebug if you haven't already got it.
Feb 5 '08 #2

P: 6
Yup got firebug, it just offers no support for whats returned by ajax requests.

And cheers, compleatly missed the semi-colon, working perfectly now
Thanks a lot for the help
Feb 6 '08 #3

Expert Mod 15k+
P: 16,027
Firebug does give the Ajax request response. Click on the linked requests that appear in the console.

Glad to hear that you got this problem fixed.
Feb 6 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.