Skip to main content

Bug Tracker

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:

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 $() 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" "">

<html xmlns="" >

<head runat="server">


<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();








<form id="form1" runat="server">


<h1>test jquery</h1>

<div id="customContainer"></div>

<hr />

<div id="result"></div>





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">






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)
  • (77.8 KB) - added by twisted036 September 02, 2010 07:57AM UTC.

    my JS problem

Change History (5)

Changed September 02, 2010 01:40AM UTC by dmethvin comment:1

component: coreajax
keywords: jquery(),load,scriptload script

What content-type is returned by load.aspx?

Changed September 02, 2010 08:02AM UTC by twisted036 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

I also try with the compat file [<script src=""></script>]. But I have the same problem.


Changed October 03, 2010 02:32AM UTC by snover comment:3

cc: → snover, dmethvin
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.

Changed October 14, 2010 03:13AM UTC by snover comment:4

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!

Changed November 11, 2010 11:09PM UTC by trac-o-bot comment:5

status: pendingclosed

Automatically closed due to 14 days of inactivity.