calvinmetcalf / leaflet-ajax

plugin for leaflet for ajax
https://calvinmetcalf.github.io/leaflet-ajax/example/
MIT License
365 stars 189 forks source link

[question] consume json from Ushahidi #20

Closed Lunkster closed 11 years ago

Lunkster commented 11 years ago

Hi all I try to consume locations from a Ushahidi website which deliver a kind of "dirty" json but it passas as valid in online json validators.

I get an error at leaflet.ajax.js, row 547: SyntaxError JSON parse: unexpected end of data.

http://kajakplatser.se/json

Is there a solution for this or is Ushahidi v2.7 json inedible? :-)

Cheers Henrik

calvinmetcalf commented 11 years ago

could you throw together a jsfiddle so I can see exactly what your doing?

Lunkster commented 11 years ago

The code I use is as follows, under test and somewhat dirty of course. Sent from phone and not fiddled.

Cheers

Kajakplatser

Kajakplatser

Dessa kajakplatser hämtas från kajakplatser.se som drivs mha Ushahidi

Den 22 okt 2013 01:27 skrev "Calvin Metcalf" notifications@github.com:

could you throw together a jsfiddle so I can see exactly what your doing?

— Reply to this email directly or view it on GitHubhttps://github.com/calvinmetcalf/leaflet-ajax/issues/20#issuecomment-26765855 .

Lunkster commented 11 years ago

Oh... sorry for the total lack of formatting... Den 22 okt 2013 01:27 skrev "Calvin Metcalf" notifications@github.com:

could you throw together a jsfiddle so I can see exactly what your doing?

— Reply to this email directly or view it on GitHubhttps://github.com/calvinmetcalf/leaflet-ajax/issues/20#issuecomment-26765855 .

calvinmetcalf commented 11 years ago

XMLHttpRequest cannot load http://kajakplatser.se/json. Origin http://calvinmetcalf.github.io is not allowed by Access-Control-Allow-Origin. http://kajakplatser.se/json doesn't have cors turned on

calvinmetcalf commented 11 years ago

as of 01d15576344dd391b8aba2222d7dd7f0ac76ae0d it now gives better errors for cross origin issues

Lunkster commented 11 years ago

Thanks for the info. It seems that the jsonp-url should be as follows: http://kajakplatser.se/api?task=incidents&resp=jsonp&callback=callback

When I try that I don't get any error messages, but no incidents show up. Any ideas? Cheers Henrik

calvinmetcalf commented 11 years ago

the data at that endpoint isn't actually geojson, you can use the jsonp function to download and then manually add it to the map if you want

L.Util.jsonp('http://kajakplatser.se/api?task=incidents&resp=jsonp').then(function(data){
//do stuff
});
Lunkster commented 11 years ago

ah... thanks for your time. :-)

calvinmetcalf commented 10 years ago

this isn't open layers

On Mon, Jul 21, 2014 at 4:50 AM, neogeomat notifications@github.com wrote:

How can i do the jsonp request with OpenLayers? i tried roadreport = OpenLayers.Request.GET({url:" http://kathmandulivinglabs/roadreporter/api/?task=incidents&resp=jsonp&callback=callback "}) and it gives net::ERR_NAME_NOT_RESOLVED error.

— Reply to this email directly or view it on GitHub https://github.com/calvinmetcalf/leaflet-ajax/issues/20#issuecomment-49583275 .

-Calvin W. Metcalf

calvinmetcalf commented 10 years ago

you might try http://gis.stackexchage.com

On Mon, Jul 21, 2014 at 5:17 AM, Calvin Metcalf calvin.metcalf@gmail.com wrote:

this isn't open layers

On Mon, Jul 21, 2014 at 4:50 AM, neogeomat notifications@github.com wrote:

How can i do the jsonp request with OpenLayers? i tried roadreport = OpenLayers.Request.GET({url:" http://kathmandulivinglabs/roadreporter/api/?task=incidents&resp=jsonp&callback=callback "}) and it gives net::ERR_NAME_NOT_RESOLVED error.

— Reply to this email directly or view it on GitHub https://github.com/calvinmetcalf/leaflet-ajax/issues/20#issuecomment-49583275 .

-Calvin W. Metcalf

-Calvin W. Metcalf