jQuery: The Write Less, Do More JavaScript Library

Ticket #1598 (closed bug: fixed)

Opened 1 year ago

Last modified 11 months ago

Execution of JavaScript code in AJAX response in IE and Safari

Reported by: diz Assigned to: anonymous
Type: bug Priority: major
Milestone: 1.2.1 Component: core
Version: 1.2 Keywords: domManip ajax javascript response
Cc: Needs: Review

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.

Attachments

Change History

Changed 1 year ago by diz

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

Changed 11 months ago by john

  • status changed from new to closed
  • resolution set to fixed

Fixed in SVN rev [3296].

Changed 11 months ago by diz

By solving this bug, you created that one: http://dev.jquery.com/ticket/1698

Note: See TracTickets for help on using tickets.