Bug Tracker

Opened 10 years ago

Closed 10 years ago

#14259 closed bug (wontfix)

script not eval when using append code block in ajax loaded text

Reported by: skovalev Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:

Description

when I'm using append twice(in ajax loaded text)some inserted scripts not called, in example bellow, if I using ajax call to add this code block and alert(1) will never call, it was already cached on previous append.

<script>
    alert(2)
    $(function() {
        $("#test").appendTo($("#test2"))
    })
</script>
<div id="test">
    test1
    <script>
        alert(1)
    </script>
</div>
<div id="test2">
    test2
</div>

http://jsfiddle.net/WZwME/2/

if i used jquery 1.7.2 alert will call as expected http://jsfiddle.net/WZwME/3/

Problem what I found is in this line

if ( rscriptType.test( node.type || "" ) &&
!data_priv.access( node, "globalEval" ) && jQuery.contains( doc, node ) )

line !data_priv.access( node, "globalEval" ) returns false

Change History (4)

comment:1 Changed 10 years ago by dmethvin

Resolution: notabug
Status: newclosed

This is intentional, otherwise scripts are executed multiple times. The old behavior was a bug.

comment:2 Changed 10 years ago by skovalev <[email protected]…>

But now it ever not been executed. Could you call script at least one time, or explain me why alert(1) not been called in example? Ps. If I remove appendTo alert would call as expected Compare this code below, please http://jsfiddle.net/WZwME/2/ http://jsfiddle.net/WZwME/4/

Thanks

comment:3 Changed 10 years ago by dmethvin

Resolution: notabug
Status: closedreopened

The first code block manipulates the second code block, the .appendTo() runs immediately since the document is ready. jQuery's assumption is that since the code is already in the document it was run when the page loaded.

Your code is just too tricky, I don't think we want to sanction doing something like this and try to create defined behavior out of it. The API documentation does not create an expectation something like this should work.

comment:4 Changed 10 years ago by dmethvin

Resolution: wontfix
Status: reopenedclosed
Note: See TracTickets for help on using tickets.