Sunday, February 3, 2013

ArcGIS quakes example unexpected token < error

I have been playing with one of the example ArcGIS samples from the 'Building Web Applications Using the ArcGIS API for JavaScript' and kept getting an annoying error:


esri.request failed: SyntaxError: Unexpected token < quakes.js:164

  1.  

Which stops the quakes layer loading.

The esri.request method requires a web server running hosting the example and a proxy page to call the quakes XML service:


function requestQuakes(){
esri.config.defaults.io.proxyUrl = "proxy.php"; //relative - if proxy.php is in the same application as the web page

var requestHandle = esri.request({
 url: "http://earthquake.usgs.gov/earthquakes/feed/geojson/1.0/week",
 load: requestSucceeded,
 error: requestFailed
}, {
 useProxy: true // changed from True
});
}



When I run it under the EasyPHP server that error came up. 

I chased the error down to the proxy.php script echoing out error messages due to uninitialized variables and missing keys from arrays.  Once I had eliminated those errors the page loaded correctly.  It seems the error messages were getting returned with the usgs earthquakes JSON and messing up the dojo JSON parser.

The new proxy.php