views:

333

answers:

1

I have a JSON feed (which I don't directly control, I have to ask the server admins to update it), that is returning NULL, or otherwise not working when I try to access it from another server. The actual feed works fine, but I can't get it to work like a normal API.

Why can I use Flickr, WhitePages, Twitter, etc's JSON APIs, but for:
http://portlandoregon.gov/shared/cfm/json.cfm

It returns NULL in the browser when using JS. If I call it on the same server, it's fine though.

If this is a server issue, what do I ask the admins to change, and if this is a local (browser) based issue, what am I doing wrong for this one feed that works for every other JSON API?

+2  A: 

They have set the content type to text/html instead of application/json. So if you're using jQuery $.ajax or $.get instead of $.getJSON, then you need to instruct it to handle it as application/json so that it will automatically parse it as JSON.

On the other hand, if really no data is been returned, then they are maybe checking who/what is requesting it and blocking it. The only resort is indeed to contact them. It might be a bug, or it might be awarely builtin to prevent leeching.

BalusC
Thanks, but I have exclusively been using $.getJSON for JSON feeds, including the portlandoregon.gov one above, but the callback in jQuery is returning NULL. So, are you saying I should tell the admin team to change what application/json to text/html and then if i use $.getJSON it will read as JSON from server to server? Might be a stupid question, but how do I check what the document type is set as (app/json or text/html)?
Oscar Godson
If `$.getJSON` returns null, then the "problem" is indeed in the server side. This might be programmatically workaroundable, but I wouldn't do that. There may be legal reasons that they block this and you don't want to escalate this. I use Firefox/Firebug to check HTTP request/response headers.
BalusC
Thanks a lot, finally someone got it. I asked this on StackOverflow in a different way and no one knew why!My supervisor told me just to tell him what he needs to tell the server admins to make it work as this is going to be used for an internal API which will need to go out to other domains and will be worked on by front end developers. So what do I need to tell them exactly to make this work with getJSON for the front end guys?Thanks a ton!
Oscar Godson
I am not sure if this is server-config related, it would have been a htaccess/web.config rule or something like that which is pretty advanced and specific, that I would be surprised if the serveradmin knew nothing about it. It seems to be more programming related, maybe it's checking the request headers to determine where it did originate and returning the response based on this condition.
BalusC