Eval multiple lines of ajax response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bodyloss
    New Member
    • Feb 2008
    • 6

    Eval multiple lines of ajax response

    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:
    Code:
    function sendData(url, pars) {
    var myAjax = new Ajax.Request ( url, {method: 'get', parameters: pars, onLoading: showLoading, evalJS: true} );
    }
    Ive set up a test, where the php script that generates the response returns:
    Code:
    $('top_left').innerHTML = 'test';
    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:
    Code:
    $('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>';
    new Draggable("search", {ghosting:true, revert:true});
    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
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    • Bodyloss
      New Member
      • Feb 2008
      • 6

      #3
      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

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        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.

        Comment

        Working...