Side navigation
#6973 closed bug ()
Opened August 31, 2010 12:32PM UTC
Closed November 11, 2010 11:09PM UTC
Last modified March 13, 2012 10:00PM UTC
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: |
Description
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 :
<div>
<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>
</div>
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 ?
thanks
Attachments (1)
Change History (5)
Changed September 02, 2010 01:40AM UTC by comment:1
component: | core → ajax |
---|---|
keywords: | jquery(),load,script → load script |
Changed September 02, 2010 08:02AM UTC by comment:2
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.
Thanks
Changed October 03, 2010 02:32AM UTC by comment:3
cc: | → snover, dmethvin |
---|---|
milestone: | 1.4.2 → 1.4.3 |
priority: | → low |
type: | feature → bug |
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.
Changed October 14, 2010 03:13AM UTC by comment:4
status: | new → pending |
---|
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!
Changed November 11, 2010 11:09PM UTC by comment:5
status: | pending → closed |
---|
Automatically closed due to 14 days of inactivity.
What content-type is returned by load.aspx?