5

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.

Deen
  • 611
  • 2
  • 16
  • 30

5 Answers5

2

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.

dennypanther
  • 53
  • 1
  • 10
0

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>
sandeep soni
  • 303
  • 1
  • 12
  • I have added jquery. Without jquery, we cannot use load(). Problem is load() is working, external script is not including – Deen Jun 23 '15 at 05:03
  • I think you are using secure server(https). then external file will not load then you need to download external file on your server. – sandeep soni Jun 23 '15 at 05:09
0

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

Aaron Cicali
  • 1,496
  • 13
  • 24
0

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>
Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
0

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.

Lakhan
  • 12,328
  • 3
  • 19
  • 28