开发者

Javascript error messages difficult to understand

There are a number of JavaScript error messages that I see on this page when I look with Chroms's JavaScript tool. I am having trouble understanding why they happen. Here is the page:

http://www.comehike.com/out开发者_开发问答doors/parks/trailhead.php

Any idea what is the problem with it?


Google Console:

Uncaught TypeError: Cannot read property 'documentElement' of null trailhead.php: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 is null, which means the request is either not receiving anything or not receiving valid XML. And it turns out to be the latter:

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.

In any case, the attribute construction error is because you had (formatted here for legibility):

<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." />

You have to escape the "T." as &quot;T.&quot;.

Honestly, these error messages aren't difficult to understand. If anything, they're incredibly helpful.


The one problem I see is invalid XML received by AJAX request. There are quotes which are not converted to HTML entities.

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...
...-------------------------------------------------^


You need to make sure your ajax call is status ok before you try to access the data

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

Also your xml response is not well formed

http://www.comehike.com/outdoors/parks/trailhead_ajax.php gives an error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜