Ticket #1598 (closed bug: fixed)
Execution of JavaScript code in AJAX response in IE and Safari
| Reported by: | diz | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.2.1 |
| Component: | core | Version: | 1.2 |
| Keywords: | domManip ajax javascript response | Cc: | |
| Blocking: | Blocked by: |
Description
Hello,
There's a problem for the execution of JavaScript mixed with HTML when loaded and integrated to the page through an AJAX.
Some of the <SCRIPT> elements don't get executed by Internet Explorer and Safari! This seems to be an error in the jQuery domManip() method which only looks for <SCRIPT> elements placed at the root of the loaded HTML.
The following AJAX response will work, the JavaScript will be executed, the paragraph will have two classes ('test' and 'ok'):
<div>
<p class="test">test</p>
</div>
<script type="text/javascript" >
$('.test').addClass('ok');
</script>
But the following JavaScript will NOT be executed, the paragraph will only have the class 'test':
<div>
<p class="test">test</p>
<script type="text/javascript" >
$('.test').addClass('ok');
</script>
</div>
This worked in jQuery 1.1.3.1 but doesn't work anymore for 1.1.4 or 1.2! Here is a minimized test case: http://wh.ysagoon.com/diz/tmp/jquery/ajax/?jquery=1.1.3.1
The JavaScript MUST be placed at the root of the DOM of the AJAX response, or it will not be executed in IE or in Safari. This is quite a problem in my case, where the AJAX response can be quite long and where the JavaScript is used to enhance the markup to make graphical enhancement (such as rounded corners). The whole response is within a <DIV> container, but the JavaScript should be placed immediately after each element which has to be decorated to avoid a styling flash.
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Have also a look at the following ticket, which seems to be the same bug (without any AJAX): http://dev.jquery.com/ticket/1594