1

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

4
  • Well, doesn't $(document).ready() is for exactly that (which is already done in .js file)? Commented Mar 3, 2011 at 2:25
  • I'm facing similar situation where $(document).ready() is not really working under Safari, but works fine with other browsers. So I'm curious to know the answer to this question. Commented Mar 3, 2011 at 2:32
  • I wasn't using a ready function at all. Would that work without eval() if the code was loaded with AJAX? Commented Mar 3, 2011 at 2:33
  • Can you review your question and add more detail. What does the ? refer to and in what are you including when you say "I include the script in the and call..."? Commented Mar 3, 2011 at 9:36

2 Answers 2

1

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().

Sign up to request clarification or add additional context in comments.

2 Comments

That is exactly my problem. Is there any problem with using eval this way? I have seen all over that it is "bad."
Using eval is a code smell in javascript because it usually means you don't know the "right" way to do something and it also can be unsafe in some situations to eval a string. In this case, however, it's ok. You can also take a look at jslint (jslint.com/lint.html) if you want to see how your code holds up against some javascript best practices.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.