谷歌地图-难以理解的Javascript错误消息

google maps - Javascript error messages difficult to understand

本文关键字:Javascript 错误 消息 谷歌地图      更新时间:2023-09-26

当我使用Chroms的JavaScript工具查看时,我在这个页面上看到了许多JavaScript错误消息。我很难理解为什么会发生这种事。这是页面:

http://www.comehike.com/outdoors/parks/trailhead.php

知道它有什么问题吗?

谷歌控制台:

未捕获类型错误:无法读取nulltrailhead.php的属性"documentElement":84

trailhead.php:

request.onreadystatechange = function()
{
      if (request.readyState == 4)
      {
            var xmlDoc = request.responseXML;
            ...
            // obtain the array of markers and loop through it
            markers = xmlDoc.documentElement.getElementsByTagName("marker");

xmlDoc为null,这意味着请求没有接收到任何内容或没有接收到有效的XML。事实证明是后者:

trailhead_ajax.php:

This page contains the following errors:
error on line 21 at column 2381: attributes construct error
Below is a rendering of the page up to the first error.

在任何情况下,属性构造错误都是因为您有(为了易读性而在此处格式化):

<marker trailhead_name="Parrish Creek Trail" 
        trailhead_description="From Interstate 15 take Centerville exit 319.
                               Go east on Parrish Lane. At 700 East turn left
                               at the "T." Follow the narrow road to the
                               trailhead." />

您必须将"T."转义为&quot;T.&quot;

老实说,这些错误信息并不难理解。如果说有什么不同的话,那就是它们非常有帮助。

我看到的一个问题是AJAX请求接收到无效的XML。有些引号没有转换为HTML实体。

XML Parsing Error: not well-formed Location: moz-nullprincipal:{ae7bee0f-3857-5344-ac34-31cd2a941e51} Line Number 21, Column 5841:
...t on Parrish Lane. At 700 East turn left at the "T." Follow the narrow road t...
...-------------------------------------------------^

在尝试访问数据之前,您需要确保您的ajax调用状态良好

if (request.readyState == 4 && request.status == 200)

此外,您的xml响应不是格式良好的

http://www.comehike.com/outdoors/parks/trailhead_ajax.php给出错误。