“JSON”是 Internet Explorer 中 JavaScript 中的未定义错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5339232/
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-08-23 16:45:01  来源:igfitidea点击:

'JSON' is undefined error in JavaScript in Internet Explorer

javascriptjqueryjsoninternet-explorer

提问by ashishjmeshram

We are using jQuery in our application. We have used a jQuery plugin to implement JavaScript session.

我们在我们的应用程序中使用 jQuery。我们使用了一个 jQuery 插件来实现 JavaScript 会话。

It is working properly in Firefox and most Internet Explorer 8 browsers.

它可以在 Firefox 和大多数 Internet Explorer 8 浏览器中正常工作。

But in some Internet Explorer 8 browsers it does not work. It gives the following error.

但是在某些 Internet Explorer 8 浏览器中它不起作用。它给出了以下错误。

Message: 'JSON' is undefined
Line: 6
Char: 3
Code: 0


Message: '$.namesession' is null or not an object
Line: 53
Char: 2
Code: 0

`

`

The version of Internet Explorer in both the cases is same.

两种情况下 Internet Explorer 的版本相同。

But there were some differences in Internet Explorer settings like Use SSL3.0and Enable Smart Screen filterscheck boxes in the Advanced tab in the Internet options were unchecked.

但是 Internet Explorer 设置中存在一些差异,例如未选中 Internet 选项中高级选项卡中的使用 SSL3.0启用智能屏幕过滤​​器复选框。

When we checked it, it started working. When we unchecked them it was still working.

当我们检查它时,它开始工作。当我们取消选中它们时,它仍然有效。

What is the actual problem in IE8?

IE8 中的实际问题是什么?

回答by Dalen

Maybe it is not what you are looking for, but I had a similar problem and i solved it including JSON 2 to my application:

也许这不是你要找的,但我有一个类似的问题,我解决了它,包括 JSON 2 到我的应用程序:

https://github.com/douglascrockford/JSON-js

https://github.com/douglascrockford/JSON-js

Other browsers natively implements JSON but IE < 8 (also IE 8 compatibility mode) does not, that's why you need to include it.

其他浏览器本机实现 JSON,但 IE < 8(也是 IE 8 兼容模式)没有,这就是您需要包含它的原因。

Here is a related question: JSON on IE6 (IE7)

这是一个相关的问题:IE6 (IE7) 上的 JSON

UPDATE

更新

the JSON parser has been updated so you should use the new one: http://bestiejs.github.io/json3/

JSON 解析器已更新,因此您应该使用新的解析器:http: //bestiejs.github.io/json3/

回答by marvwhere

<!DOCTYPE html>

Otherwise IE8 is not acting right. Also you should use:

否则 IE8 运行不正确。你也应该使用:

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

回答by Kainattu

Please add json2.js in your project . i was faced the same issue i have fixed.

请在您的项目中添加 json2.js。我遇到了同样的问题,我已经解决了。

please use the link: https://raw.github.com/douglascrockford/JSON-js/master/json2.jsand create new file json.js, copy the page and past into newly created file , and move that file into your web application.

请使用链接:https: //raw.github.com/douglascrockford/JSON-js/master/json2.js并创建新文件json.js,将页面复制并粘贴到新创建的文件中,然后将该文件移动到您的 Web 应用程序中。

I hope it will work.

我希望它会起作用。

回答by Alex

Check for extra commas in your JSON response. If the last element of an array has a comma, this will break in IE

检查 JSON 响应中是否有多余的逗号。如果数组的最后一个元素有逗号,这将在 IE 中中断

回答by Sunil

Change the content type to 'application/x-www-form-urlencoded'

将内容类型更改为“application/x-www-form-urlencoded”

回答by Travis Heeter

I had this error 2 times. Each time it was solved by changing the ajax type. Either GET to POST or POST to GET.

我有 2 次这个错误。每次都是通过改变ajax类型解决的。GET 到 POST 或 POST 到 GET。

$.ajax({
        type:'GET', // or 'POST'
        url: "file.cfm?action=get_table&varb=" + varb
    });

回答by Stefan Michev

I had the very same problem recently. In my case on the top of a php script I had some code generationg obviously some extra output to the browser. Removal of empty lines (between ?> and html-tag ) and simple cleanup helped me out:

我最近遇到了同样的问题。就我而言,在 php 脚本的顶部,我生成了一些代码,显然还有一些额外的输出到浏览器。删除空行(在 ?> 和 html-tag 之间)和简单的清理帮助了我:

<?php 
include('../config.php');

//

ob_clean();
?>
<!DOCTYPE html>