Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery `.load()` function not executing javascript which is in loading page

Tags:

html

jquery

ajax

What I'm trying to do is load an external html file and have the Javascript that is embedded execute along with the html code that I had in my Loading_Page.html.

The code I'm trying to use is this:

$("#myBtn").click(function() {
  $("#myDiv").load("Loading_Page.html");
});

Loading_Page.html looks like this (simple now, but will expand once/if I get this working).It has both html and javascript, so I need to get Html page along with the javascript.

<html> 
<head>
  <title>Tracking HTML File</title>
  <script language="javascript" type="text/javascript">
    alert("outside the jQuery ready");
  </script>
</head>

<body>

  <div id="first_division"><img src="someimage.jpg" alt="image" /></div>
  <div id="second_division"><p>some text</p></div>
</body>

</html>

But the javascript in Loading_Page.html page is not executing along with the html code in Loading_Page Any thoughts on why the browser is ignoring the Javascript in the Loading_Page.html file?

Thanks for your help in advance!

like image 559
venkat Avatar asked Dec 12 '25 19:12

venkat


1 Answers

jQuery load will just exclude that script tag from response, before it is inserted into a div.

See this question. The same problem happens there.

like image 88
Viktor S. Avatar answered Dec 15 '25 08:12

Viktor S.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!