Opened 12 years ago

Closed 12 years ago

#6887 closed bug (notabug)

triggered twice with emebedded script tag problem

Reported by: ling Owned by:
Priority: minor Milestone: 1.9.0
Component: ui.dialog Version: 1.8.8
Keywords: Cc:
Blocked by: Blocking:

Description

When I load the content of /test/anycontent.php

<div>
    <h1>My title</h1>
    <p>This is a paragraph</p>
    <script type="text/javascript">
//        alert("it seems that the presence of script tags is enough to trigger the problem");
    </script>
</div>

into jquery ui dialog, the result is buggy using the $.post method, and clean using the load method.

Here is the test with post method

$("#test").click(function(e){
           $.post(url, {}, function(data){
                $(data).dialog();
            });
        });

And here the test with get method

 $("#test").click(function(e){
            $("<div></div>").load(url).dialog();
        });

Then my problem is that with the post method, I will have 2 instances of ui-dialog !! only one was expected, the other is just in the middle of the first one, and it is empty and closed.

Do you know why ? Do you know issues for this ?

Change History (3)

comment:1 Changed 12 years ago by shrage.smilowitz

For some reason (dont know why) if you pass in html elements in a jquery selector liek this $(<div><script></script></div> it will return them as a list of results div as item1 and script as item2

The dialog function (also for some reason i don't know) runs an each function of the selectors results, for each item in the selector it will create a dialog. so it will create a dialog for the normal html elements of your data and for the script element. what i'm doing is this:

var all = $(data); for (i = 0; i < all.length; i++) {

if (all[i].tagName == "SCRIPT") {

$("body").append(all[i]); If i don't append it to the body it wont evaluate the script

} else {

$(all[i]).dialog();

}

}

comment:2 in reply to:  1 Changed 12 years ago by ling

Replying to shrage.smilowitz:

For some reason (dont know why) if you pass in html elements in a jquery selector liek this $(<div><script></script></div> it will return them as a list of results div as item1 and script as item2

The dialog function (also for some reason i don't know) runs an each function of the selectors results, for each item in the selector it will create a dialog. so it will create a dialog for the normal html elements of your data and for the script element. what i'm doing is this:

var all = $(data); for (i = 0; i < all.length; i++) {

if (all[i].tagName == "SCRIPT") {

$("body").append(all[i]); If i don't append it to the body it wont evaluate the script

} else {

$(all[i]).dialog();

}

}

Thank you, I did it a similar way too.

comment:3 Changed 12 years ago by Scott González

Resolution: invalid
Status: newclosed

This is not a bug in jQuery UI. Please use the forums for help.

Note: See TracTickets for help on using tickets.