【问题标题】:jQuery / AJAX / parsererror / XAMPP / Win8.1 / IE11 / ChromejQuery / AJAX / parsererror / XAMPP / Win8.1 / IE11 / Chrome
【发布时间】:2014-11-15 20:59:08
【问题描述】:

我知道有一百万个关于“parsererror”的问题,但似乎找不到适合我情况的答案。这是我的病态代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Test</title>

<script type="text/javascript" src="jquery-2.1.1.min.js"></script>

<script type="text/javascript">
    $.ajax({
        url: 'http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0',
        dataType: 'jsonp',
        contentType: 'application/jsonp; charset=utf-8',
        jsonp: 'onscriptload',
        success: function(data, textStatus)
            {
                console.log("Success."); 
                var MM = Microsoft.Maps;
                var map = new MM.Map($('#mapDiv')[0],
                    {
                        credentials: 'a valid bing maps key'
                    });
            },
        error: function(xOptions, textStatus)
            {
                console.log(JSON.stringify(xOptions) + ' ' + textStatus);
            }
        });
</script>
</head>
<body>
    <div id="mapDiv" class="map"></div>
</body>
</html>

“错误”部分被触发,并返回{"readyState":4,"status":200,"statusText":"load"} parsererror,我很难让它工作。 IE11 和 Chrome 中的错误/行为完全相同。这是最有帮助的文章 (Callback function for JSONP with JQuery ajax),但“onscriptload”应该已经是我不应该(重新)定义/重载的内置函数,不是吗?任何帮助表示赞赏...

【问题讨论】:

  • 那个 url 是一个脚本。你为什么要把它当作 jsonp 对待?
  • 我正在尝试遵循代码示例here

标签: javascript jquery ajax parse-error


【解决方案1】:

那个 ajax 请求是一个“hack”,目的是按需加载 bing 地图库,而不是在页面加载时加载。我会推荐一种典型的方法,例如:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

      <script type="text/javascript">

          function loadMap() {
              // Initialize the map
              var map = new Microsoft.Maps.Map(document.getElementById("map"),
              {
                  credentials: "BING MAPS KEY HERE"
              });

              //load the pushpins here
          }

      </script>
   </head>
   <body onload="loadMap();">
        <div id="map"></div>
   </body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    • 2014-07-27
    • 2011-06-30
    • 2015-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多