views:

21

answers:

1

So I am planning on dynamically changing a page's content by fetching it from another page.

To do so, I used Mootools' Request class:

var tabContent = new Request({
    url: 'foo/bar/baz.php',
    onSuccess: function(data) {
        $('tab_container').innerHTML = data;
    }
}).send();

In any case, the HTML is fetched fine, and returns without a hitch. However, I'd like to add some events to THOSE fetched elements (Fx.slide, to be precise), and that requires some js to be included in the requested file.

Upon inspection of the returned data, the javascript is intact. However, it does not show up in the final product. That is, somewhere in between having received the data, and rendering the data (via the innerHTML bit) it seems as though the javascript has been excised out for some reason.

Hm.

+1  A: 

add evalScripts: true to the Request options, then include the script in a simple <script></script> block at the bottom of the response.

Dimitar Christoff
Thanks, Dimitar. As I've also found out, Request.HTML excises out the js and puts it into responseJavascript, and $exec will run it.
Julian H. Lam