1

I am trying to consume this JSON web service: http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_week.geojson

I have tried the following code:

$.ajax({
    url: url,
    type: 'GET',
    crossDomain: true,
    dataType: 'json',
    jsonp: false,
    success: function() { alert("Success"); },
    error: function() { alert('Failed!'); }});
}

I get the following error in chrome :

XMLHttpRequest cannot load ...earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_week.geojson. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost' is therefore not allowed access.

I have seen all the suggestions for changing datatype to jsonp but this doesn't work in my case because this service does not provide jsonp data. Is there is any other way to parse this data with JavaScript?

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
p. leo
  • 48
  • 1
  • 1
  • 7
  • You are out of luck here. You can set up server proxy and request it instead. – dfsq Sep 21 '14 at 16:04
  • Looks that to use server proxy on the same domain is the only way. See this answer for example http://stackoverflow.com/a/11605168/1105860 – Roman Bekkiev Sep 21 '14 at 16:13
  • "because this service does not provide `jsonp` data" - have you tried this url: http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/significant_week.geojsonp – Stephan Muller Sep 21 '14 at 16:29
  • Thank you all for the help. The proxy method didnt work for me. But as Stephan Muller said this service provides jsonp data and i haven't realized it. So my problem solved. – p. leo Sep 21 '14 at 20:21

0 Answers0