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
5 Answers
Reset to default 2Check 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
版权声明:本文标题:javascript - External file script is not loading - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744139592a2592556.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论