当我查看Chroms的JavaScript工具时,我在此页面上看到了许多JavaScript错误消息。我无法理解他们为什么会这样。这是页面:
http://www.comehike.com/outdoors/parks/trailhead.php
知道它有什么问题吗?
答案 0 :(得分:1)
我看到的一个问题是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...
...-------------------------------------------------^
答案 1 :(得分:1)
在尝试访问数据之前,您需要确保您的ajax调用状态正常
if (request.readyState == 4 && request.status == 200)
你的xml响应也没有很好地形成
http://www.comehike.com/outdoors/parks/trailhead_ajax.php 给出错误。
答案 2 :(得分:1)
Google控制台:
未捕获TypeError:无法读取null trailhead.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。结果证明是后者:
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."
转义为"T."
。
老实说,这些错误信息并不难理解。如果有的话,他们会非常有帮助。