Scott Colby
Scott Colby

Reputation: 1430

Modifying Javascript to run after AJAX load

I am using a little javascript thingy (app?) from http://code.google.com/p/tumblrbadge/ to load my most recent tumblog post into my webpage. However, when I load the 'tumblr' section with AJAX using Jquery, the script does not get executed. I understand why this is and that I need to include the javascript file in the and execute it after the AJAX load is complete. My problem is this: I do not fully understand the tumblrbadge code and, when I include the script in the and call tumblrBadge() after loading, it does not run. How must I modify the tumblrbadge code to allow it to be run on demand from the ?

All of this is hosted at http://jquerytest.webs.com

Upvotes: 1

Views: 923

Answers (2)

Ryre
Ryre

Reputation: 6181

Try $(window).onload instead of $(document).ready.

Upvotes: 0

tilleryj
tilleryj

Reputation: 14379

It looks like your problem is that the script tags within the tumblr section of your site are not being executed. When you insert html into a page using ajax, you have to parse out the contents of any script tags and execute them separately.

After the content of the tumblr tab is inserted in your page, get all of its script tags with $("#contentOfTumblrTab script") and evaluate their innerHTML using eval().

Upvotes: 1

Related Questions