JSON Feed Returns null when using jQuery getJSON

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

It returns null. I do not have access to this. I need the server administrator to update the feed to your liking, so if you can tell me how to make it work as it is, without adding tags to my HTML, please let me know. I will use this with jQuery, and I'm trying to use getJSON, which returns null.

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

which returns null. But if I use flickr stream, for example, it works fine. it returns what it should, [onject Object]. Any ideas?

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

+4
source share
2 answers

JSON is not valid. Cut and paste it at http://www.jsonlint.com/ for more information on syntax error. The JSON parser you use fails, maybe the other will be softer.

+4
source

I think that () around your JSON output is what causes a null return. I would check json.cfm output and delete ()

Update:

It is assumed that () should restrict the remote call using jsonp .

I just checked the local output test in the local file and it works.

Using both parameters:

 $.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 } }); 

Cross scripting issues should be properly avoided.

I get a clean response in firebug for both of these requests. key sends data type "jsonp"

Additional information about jsonp .

See if they help you:

Make cross-domain Ajax queries with jQuery

Dashboard Cross-Domain AJAX with jquery

+1
source

Source: https://habr.com/ru/post/1303872/


All Articles