views:

1903

answers:

3

http://portlandonline.com/shared/cfm/json.cfm?c=27321

It's returning null. I don't really have access to this. I have to have a server admin update the feed to my liking, so if you can tell me how to get this to work as is, without adding tags to my HTML please let me know. I will be using this with jQuery, and ive been trying to use getJSON which is what returns null.

$.getJSON('http://portlandonline.com/shared/cfm/json.cfm?c=27321',function(json){
    alert(json);
});

that returns null. But if i use a flickr feed for example, it works fine. it returns what it should, [onject Object]. Any ideas?

Edit: I found out it was because the HTTP response headers were set to application/json and should be set to text/html

+2  A: 

The JSON is not valid apparently. Cut and paste it into http://www.jsonlint.com/ for more details on the syntax error. The JSON parser you are using is failing, perhaps another one will be more lenient.

Sean A.O. Harney
The parser is jQuery itself :) The problem is as you say, but the only fix is to fix the JSON itself in 1.4+, which is the better solution anyway.
Nick Craver
Yes, it looks like the server-side JSON generation is getting messed up somehow and it is not valid JSON. Perhaps you could fix it up and transform it to valid json if it is an important feed.
Sean A.O. Harney
Oscar Godson
+1  A: 

I think the ( ) around your JSON output are what is causing the null return. I would check the json.cfm output and remove the ( )'s

Update:

The ( ) are supposed to border a remote call using jsonp.

I just ran a local test of the output in a local file and it works.

Using both:

$.getJSON("http://portlandonline.com/shared/cfm/json.cfm?c=27321", function(data){
   alert( data );
  });

and :

$.ajax({
    dataType: "jsonp", 
    url: 'http://portlandonline.com/shared/cfm/json.cfm?c=27321',
    success: function(data) {
     ...do stuff
    }   
   });

Should properly avoid any cross domain scripting issues.

i get a clean response in firebug for both these requests. the key is sending the datatype "jsonp"

More info on jsonp.

See if these help you also:

Make cross-domain Ajax requests with jQuery

Dashboard Cross-domain AJAX with jquery

ethyreal
Oscar Godson
seems to be a permission issue
ethyreal
Hmm, i don't get why I can't figure this out... I consider myself extremely fluent in jQuery, anyways:$.getJSON("http://portlandonline.com/shared/cfm/json.cfm?c=27321", function(data){ alert( data ); }); $.ajax({ dataType: "jsonp", url: 'http://portlandonline.com/shared/cfm/json.cfm?c=27321', success: function(data) { alert('success!'); } });doesn't give me the success alert... could you send me all your code? my email is [FirstnameLastname(AT)gmail]Thanks, i think im just being stupid :)
Oscar Godson
+1  A: 

I'm having the same issue with a valid JSON. Any thoughts?

Diego
Yeah, someone finally helped me out when I rephrased the question ;)http://stackoverflow.com/questions/2448995/making-json-feed-work-server-to-server
Oscar Godson