Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#6973 closed bug

Load JS script inside HTML

Reported by: twisted036 Owned by:
Priority: low Milestone: 1.4.3
Component: ajax Version: 1.4.2
Keywords: load script Cc: snover, dmethvin
Blocked by: Blocking:


I want to change from 1.3.2 to 1.4.2 but I block facing unexpected behavior :

The code <script type="text/javascript"></script> is filter when I use $() http://api.jquery.com/jQuery/ with a context. The javascript inside the HTML is not executed.

An example :

Page which called another with Ajax

<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 TransitionalEN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">

<title></title> <script src="jquery-1.4.2.js" type="text/javascript"></script> <script type="text/javascript"> $.get("load.aspx", function(data) { alert("Data Loaded: " + data); var content = $("#content", data).html(); $("#customContainer").html(content); alert(data); alert(content); }); </script>

</head> <body>

<form id="form1" runat="server"> <div> <h1>test jquery</h1> <div id="customContainer"></div> <hr /> <div id="result"></div> </div> </form>

</body> </html>

Page which is called by the first one :


<strong>du html</strong> <p id="content"> <span style="color: Red">toto</span> <br />

<script type="text/javascript"> alert("titi"); </script>

<span>tutu</span> </p>


The line var content = $("#content", data).html(); delete the JS code. This code works great with jQuery 1.3.2 I can see the code JS disappear with the alerts : alert(data); I have all the code of the page with the JS inside the HTML alert(content); I want only the content of the div "content" with the JS, but the javascript disappear Is it the normal behavior ? How load the script when it is located inside the HTML ?


Attachments (1)

jqueryJSProblem.zip (77.8 KB) - added by twisted036 12 years ago.
my JS problem

Download all attachments as: .zip

Change History (6)

comment:1 Changed 12 years ago by dmethvin

Component: coreajax
Keywords: jquery() removed

What content-type is returned by load.aspx?

Changed 12 years ago by twisted036

Attachment: jqueryJSProblem.zip added

my JS problem

comment:2 Changed 12 years ago by twisted036

The content-type is text/html. The loading with Ajax works great, I have all the source code (html+js) from the target page in the var "data".

The problem appear when I want only the code inside the div "content". There are some JS inside this div. I use var content = $("#content", data).html(); In my var content, I don't have the JS anymore. I have the same problem with the method find().

I upload my problem in attachment file. I don't know if it's a bug or if I miss something. I don't see anything which can be linked to my problem in this page http://jquery14.com/day-01/jquery-14#backwards

I also try with the compat file [<script src="http://code.jquery.com/jquery.compat-1.3.js"></script>]. But I have the same problem.


comment:3 Changed 12 years ago by snover

Cc: snover dmethvin added
Priority: low
Type: featurebug

We need to do a better job of documenting what happens when you try to load an entire page via AJAX instead of a page fragment—and what happens when you try to load in scripts.

comment:4 Changed 12 years ago by snover

Status: newpending

This ticket has been marked as missing a test case. In an effort to reduce the number of outstanding tickets in the bug tracker, it will be closed automatically in 30 days. In order to prevent this from happening, please provide a working test case. If a test case has already been provided and our records are wrong, please respond to the ticket so that it can be fixed. Thank you!

comment:5 Changed 12 years ago by trac-o-bot

Status: pendingclosed

Automatically closed due to 14 days of inactivity.

Note: See TracTickets for help on using tickets.