5
votes

Iam using load() for loading external html file.

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

Here, HTML file is loaded and css also loaded but script file is not loading in the page

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

I tried to declare the above script file inside the head and inside the body. Both are not working.

5
Are you sure js/utility.js exists? Do you see any console logs indicating a 404 or similar error? - Zack Tanner
There is no error and files also exists. But that files are loaded in html page - Deen
link to js file is inside header.html ? - Dimag Kharab
This files is used for partcular page only. not for all page. Thats y i given in another html file not in header.html - Deen
Can you bebug and check whether .js is loading or not. - Lasitha Benaragama

5 Answers

2
votes

Check your relative path to the utility.js file and make sure to load juery.js library before load utility.js file.

and finally try this,

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

to load the utility.js file.

0
votes

I think you forget to add 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
votes

jQuery may only execute your code with the type attribute set to "text/javascript", per this bug filed a long time ago:

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

0
votes

Try this ...

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

The jQuery code that adds HTML to the DOM always strips out <script> tags. It runs them and then throws them away.

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

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

In that case, the scripts are stripped and not evaluated/run.