External script file not loading

Iam using load () to load an external html file.

$("#header_section").load("header.html");
$("#sidemenu_section").load("side_menu.html"); 

Here the HTML file is loaded and css is loaded, but the script file is not loaded on the page

<script src="js/utility.js"></script>

I tried to declare the above script file inside the head and inside the body. Both do not work.

+4
source share
5 answers

Check your relative path to the .js utility file and be sure to download the juery.js library before loading the .js utility file.

and finally try this,

<script type="text/javascript" src="${pageContext.request.contextPath}/js/utility.js"></script>

to download the utility.js file.

+2
source

I think you forgot to add the jquery.min.js file. use below code.

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/utility.js"></script>
</head>
0
source

jQuery , "text/javascript", , -:

http://bugs.jquery.com/ticket/3733

0

...

<script type="text/javascript" src="http://your.cdn.com/first.js"></script>
<script type="text/javascript">
loadScript("http://your.cdn.com/second.js", function(){
    //initialization code
});
</script>
0
source

The jQuery code that adds HTML to the DOM always issues tags <script>. He launches them and then drops them.

An exception to this behavior is when you use $ .load () with a hack that allows you to load a page fragment:

$.load("http://something.com/whatever #stuff_I_want", function() { ... });

In this case, the scripts are deleted and not evaluated / executed.

0
source

All Articles