IE10 and jQuery: SCRIPT5009: “$” is undefined

旧城冷巷雨未停 提交于 2019-11-27 17:23:20

问题


I'm faced with this really annoying problem, it appears in IE10 like in IE9. Given this HTML:

<head>
    <title>Any Consult</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
    <!--[if lte IE 9]>
        <script src="scripts/IE9.js"></script>
    <![endif]-->
    <script type="text/javascript" src="scripts/jquery.js"></script>
    <script type="text/javascript" src="scripts/scripts.js"></script>
</head>

This (scripts.js) works fine in FF and Chrome, but IE10 throws the SCRIPT5009 error.

scripts.js is like (simple, but tested example):

$(document).ready(function() {
   alert('Hello');
});

IE10 does not load the jQuery-File and I tried nearly everything. I changed and reduced the filename, I spared the

<!--[if lte IE 9]>...

part, I tried

src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js"

but nothing happened. Because this is a new version of this question, I'd like to specify:

  1. how should I name the jQuery-File for IE(10)?
  2. where should I put the script tags in the HTML-Header?

Thanks a lot!

EDIT: Here the suggested HTML-version, which does not work, too:

<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/scripts.js"></script>
<script type="text/javascript" src="scripts/clocks.js"></script>
<!--[if lte IE 9]>
    <script src="scripts/IE9.js"></script>
<![endif]-->
<!--[if IE]><script type="text/javascript" src="scripts/excanvas.js"></script><![endif]-->

IE9.js is a browser polyfill file.

And here is my screenshot ("ist undefiniert" means "is undefined", "Die Webseite reagiert nicht" means "the page went down", "Debugger beenden" means "stop debugging", $('.aLang') is a class in my HTML.


回答1:


I had this problem with IE and found that the jQuery javascript file was corrupt in the IE developer tool. This was caused in my case by HTTP GZIP compression being done by the server but IE wasn't decompressing the file. I guess that if you turn off static HTTP compression or exclude the application/x-javascript from whatever is doing the compression (Mine was done by FluorineFX for all files over 10Kb) it should work okay once you have cleared your browser cache to get rid of the compressed javascript file.




回答2:


Place the conditional script after the jQuery library:

<script type="text/javascript" src="scripts/jquery.js"></script>
<!--[if lte IE 9]>
<script src="scripts/IE9.js"></script>
<![endif]-->


来源:https://stackoverflow.com/questions/16882513/ie10-and-jquery-script5009-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!