admin管理员组

文章数量:1397117

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.

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.

Share Improve this question asked Jun 23, 2015 at 4:52 DeenDeen 6212 gold badges16 silver badges30 bronze badges 12
  • 1 Are you sure js/utility.js exists? Do you see any console logs indicating a 404 or similar error? – Zack Tanner Commented Jun 23, 2015 at 4:54
  • There is no error and files also exists. But that files are loaded in html page – Deen Commented Jun 23, 2015 at 4:55
  • link to js file is inside header.html ? – Dimag Kharab Commented Jun 23, 2015 at 4:56
  • 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 Commented Jun 23, 2015 at 4:58
  • Can you bebug and check whether .js is loading or not. – Lasitha Benaragama Commented Jun 23, 2015 at 4:59
 |  Show 7 more ments

5 Answers 5

Reset to default 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.

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

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

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./ticket/3733

Try this ...

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

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./whatever #stuff_I_want", function() { ... });

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

本文标签: javascriptExternal file script is not loadingStack Overflow