【问题标题】:JSON object undefined in IE compatibility mode [duplicate]IE兼容模式下未定义的JSON对象[重复]
【发布时间】:2013-10-02 03:35:36
【问题描述】:
<script type="text/javascript">
    function initialize() {
        var markers = JSON.parse('[{"title":"Chennai","lat":"12.897400","lng":"80.288000","Description":"welcome to chennai"},{"title":"Hyderabad","lat":"17.266700","lng":"78.530200","Description":"welcome to hyderabad"},{"title":"Banglore","lat":"12.897400","lng":"77.519500","Description":"welcome to Banglore"},{"title":"vishkapatnam","lat":"17.518300","lng":"83.320300","Description":"welcome to Vishkapatnam"}]');
        var mapOptions = {
            center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
            zoom: 5,
            mapTypeId: google.maps.MapTypeId.ROADMAP

        };

我得到的 JSON 是找不到 Microsoft?那我该怎么办?

【问题讨论】:

  • 您使用的是哪个版本的 IE(我想)?
  • 这很奇怪,在IE8中应该已经完全支持了,反正看这里:stackoverflow.com/questions/4908875/…
  • 几乎可以肯定是IE8在兼容模式(或怪癖模式)下造成的。
  • 我设置了IE8兼容模式,但显示的和一样

标签: javascript internet-explorer


【解决方案1】:

检查您是否处于兼容模式。 您可以通过元标记确保 IE8 不在 IE7 模式下呈现

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

或者最好使用文档类型

<!DOCTYPE html>

【讨论】:

    【解决方案2】:

    在你的代码之前的某个地方:

    window.JSON || 
        document.write('<script src="https://cdnjs.cloudflare.com/ajax/libs/json3/3.2.4/json3.min.js"><\/script>');
    

    【讨论】:

    • 但显示的和先生一样
    • 什么给出警报(typeof window.JSON); ?
    • JSON.parse('');
    • window.JSON || document.write('
    • 请给我你的项目的链接..
    猜你喜欢
    • 2013-09-14
    • 2023-03-24
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 2016-07-03
    相关资源
    最近更新 更多