0x800a1391 - JavaScript 运行时错误:“JSON”在 IE 10 中未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15359938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:47:55  来源:igfitidea点击:

0x800a1391 - JavaScript runtime error: 'JSON' is undefined in IE 10

jsonvisual-studio-2012internet-explorer-10iis-8

提问by Rameez Ahmed Sayad

I'm using IE 10 Compatibility on Windows 8, I'm getting this error while running the WebApp in Debug mode(VS 2012). 0x800a1391 - JavaScript runtime error: 'JSON' is undefined Code below

我在 Windows 8 上使用 IE 10 兼容性,在调试模式(VS 2012)下运行 WebApp 时出现此错误。0x800a1391 - JavaScript 运行时错误:“JSON”未定义代码如下

var data = JSON.stringify(GetUserDetails());

function GetUserDetails() {
    var userData = {};
    userData.userName = $('#txtUserName').val();
    userData.password = $('#txtPassword').val();
    return userData;
}

Also , the strange fact is the same code hosted in IIS 8 runs fine in IE 10 Browser. Any inputs?

此外,奇怪的事实是托管在 IIS 8 中的相同代码在 IE 10 浏览器中运行良好。任何输入?

采纳答案by T.J. Crowder

IE8 and up only havethe JSONobject in standardsmode. So you need to make sure the document has a doctype.

IE8 及以上只有标准模式JSON对象。因此,您需要确保文档具有 doctype。

回答by Bern

I found out for me that it was an IE 10compatibility's intranet setting that was raising this exception for my intranet sites:

我发现它是IE 10兼容性的 Intranet 设置,导致我的 Intranet 站点出现此异常:

"Display the intranet sites in Compatibility View"

“在兼容性视图中显示 Intranet 站点”

To change this flag, or just to simply disable it, display the "Command Bar" in IE 10, then select "Tools" > "Compatibility View Settings" and un-check the option - second from the bottom. Fixed the issue immediately.

要更改此标志,或者只是简单地禁用它,请在 IE 10 中显示“命令栏”,然后选择“工具”>“兼容性视图设置”并取消选中该选项 - 底部第二个。立即修复了该问题。

enter image description here

在此处输入图片说明

回答by Mohammed Rafeeq

You need to include json2.js

你需要包含 json2.js

see json2 inclusion

json2 包含

for more details. There are cases where we have to deal with cases where clients use IE7 standards. So our code had to cater to such cases too. Ours being a retail website is accessed by hundreds of clients who use IE7 standards. Including json2 solves this issue

更多细节。在某些情况下,我们必须处理客户端使用 IE7 标准的情况。所以我们的代码也必须迎合这种情况。我们是一个零售网站,有数百名使用 IE7 标准的客户访问。包括 json2 解决了这个问题

回答by James Henderson

I had the same "JavaScript runtime error ...JSON is undefined" running Windows 8 and IE 10, while trying to run an ASP .NET application using Visual Studio 2010 development web server. When I opened the browser, clicked "Alt" to display the menu, then clicked Tools->Compatibility View Settings and unchecked "Display all websites in compatibility view", I stopped getting the error.

我在运行 Windows 8 和 IE 10 时遇到了相同的“JavaScript 运行时错误...JSON 未定义”,同时尝试使用 Visual Studio 2010 开发 Web 服务器运行 ASP .NET 应用程序。当我打开浏览器,单击“Alt”以显示菜单,然后单击“工具”->“兼容性视图设置”并取消选中“在兼容性视图中显示所有网站”时,我不再收到错误消息。