jquery ajax html response change 1.3.2 vs 1.4.2 (aka where is my script tag?)
- by cmroanirgo
I've been using jquery 1.3.2 to pull snippets of html (including script) from a server. A typical response might be:
<div id="content"<div id="inner"...
<script type=... alert("hello world");</script
<pHello World</p
</div</div
I've been using the query .get function:
$.get($(this).attr("href"), function(response) {
$("#inner").replaceWith($("#inner", response));
});
And everything is fine and works as expected: the returned html snippets get loaded into the DOM and the scripts run.
When I use 1.4.2 however, I notice that the script tags have been removed and no longer run.
Stepping into the newer jquery codebase yields the lines of code (line 4498) :
ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
which seems to be the culprit 'removing' the script from its happy resting place as part of the selector process. But it doesn't help me in injecting exactly what i want into the DOM.
Any idea why jquery is doing this? More importantly, how can I go about fixing this so that my scripts run?