views:

308

answers:

2

Using jQuery 1.4 I've come across an issue with external JS in an ajax response being removed when accessing it using html().

I'm creating an endless scrolling effect for a tumblr theme using an ajax request to load the next page. Tumblr outputs JS in audio and slideshow posts to render <embed> elements (Flash players) to show the content. The markup cannot be changed.

Everything works fine using jQuery 1.3.2, the external JS is executed and renders the players, however in 1.4 the javascript is removed and I'm left with the fallback text. The JS is included in the response, but when using html() within the ajax callback I can't retrieve or get the javascript to execute.

I want to use jQuery 1.4 because I'm using some of it's new features in other parts, I can get it to work using split but I'm not sure how reliable it is to split the response on a specific string.

I've prepared a basic sample (includes 2 files, test.html & request.html) demonstrating the issue. Open test.html to load a local request from request.html

Is this behaviour deliberate, can I get around it, or am I just doing it wrong?

A: 

This looks like a bug in 1.4 to me—I get the same results using your sample code; switching back to 1.3.2 allows the embedded scripts to execute again.

The documentation certainly doesn't mention anything about any changes in 1.4 which prevent the execution of scripts in retrieved HTML. I'd post a question at the jQuery forum and see if anyone else is having the problem; you might get the attention of one of the jQuery devs too.

Mark B
A: 

From the jQuery docs on .ajax():

If html is specified, any embedded JavaScript inside the retrieved data is executed before the HTML is returned as a string. Similarly, script will execute the JavaScript that is pulled back from the server, then return the script itself as textual data.

I'm not finding any way around it... But it seems to be behaving different from 1.3.2 and the "1.3-compat" plugin doesn't seem to fix it either.

gnarf