【问题标题】:SCRIPT5009: 'JSON' is undefined in IE 10 The value of the property '$' is null or undefined, not a Function objectSCRIPT5009:“JSON”在 IE 10 中未定义属性“$”的值为 null 或未定义,不是函数对象
【发布时间】:2013-09-15 01:37:48
【问题描述】:
   <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Hello World</title>
        <link href="StyleSheet.css" type="text/css" rel="stylesheet" />
        <script type="text/javascript" src="Scripts/jquery-2.0.3.js">
            $(document).ready(function () {

                <%--$("#width").val() = $(window).width();
                $("#height").val() = $(window).height();--%>


            });
    </script>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#width").val($(window).width());
                $("#height").val($(window).height());
            });
        </script>
    </head>
<body>
    <form id="form1" runat="server">
<input id="width" type="hidden" runat="server" />
        <input id="height" type="hidden" runat="server" />
</form>
</body>
</html>

上面是我的带有 jquery 脚本的 aspx 代码,它给出了窗口的高度和宽度。

当我从 Visual Studio http://localhost/Mypage.aspx 运行 Web 应用程序时,此代码在所有浏览器上都非常好

但是当我将它托管在 iis 上并使用我的机器名称 http://MyMachine/Mypage.aspx 运行时,它给出 JSON 未定义并且属性“$”为空或未定义错误。(这仅在 IE 10(非兼容模式)中,对于铬它工作正常)

问题 1) 我们是否需要处理 IE 10 的任何安全限制?

问题2)为什么当我将它托管在iis上并在我自己的机器上使用机器名运行它时会发生这种情况?

问题 3)我是否缺少任何 jquery 参考。

问题 4) 很明显,这个问题的任何解决方案。

【问题讨论】:

  • 是的,我说过,即使在部署后它在 Chrome 上也能正常工作。这是IE的问题。
  • 我也想试试&lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&gt;
  • 酷它工作。谢谢。你能帮我理解或指点一下那一行代码是如何解决问题的吗?
  • 我猜,默认情况下,您的 IE 工作在较低版本的兼容模式下,而不是 IE10。
  • 我已经检查了开发者工具 I4V,它在 IE 10 中运行。

标签: c# javascript jquery asp.net json


【解决方案1】:

按照很多人的建议使用 Meta 标签。

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

但我想给一个重要的提示。 mata 标签应该是 head 标签中的第一个标签。我已经读过它,如果它不是第一个标签,它不会有它的效果。

【讨论】:

  • cool 这有帮助,小费也是。我意识到它必须是第一个声明。能否请您指出您阅读它的位置。
【解决方案2】:

您确定服务器中有带有 jquery 的 Scripts 文件夹吗? 建议你用fiddler调试一下,看看jquery是否加载正确,或者是否有http错误。

【讨论】:

  • 正如 I4v 所建议的,这行代码有帮助,
【解决方案3】:

按照 I4v 的建议,将其添加到标题中也为我修复了该错误:

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

谢谢大家

【讨论】:

    猜你喜欢
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 2014-07-10
    • 2016-08-28
    相关资源
    最近更新 更多