getjson and servers
Is getJSON only useful for those who control a server? Is there any other alternative for getting data from a file?
i tried
$.getJSON("good.json", function(data){
out=out+"good.json: "+data + ","; });
where good.json = {"a":"1","b":"2"} and got a result of 'null' for data.
These all are valid JSON files, and all give null when used in the above:
good.htm assoc.json assoc.js stub.json stub.js test.js test.txt and all get a null result...The above is in an interactive 开发者_运维知识库setting at http://jsbin.com/dbJSON/8/edit
the output (of null) is to be had by clicking 'output'.
Your example tries to load
http://sn.im/g-g4g/good.json
The problem is that you are on the jsbin.com domain so you have a cross-domain issue : jsbin.com cannot make an ajax request to sn.im. This is why you get a NULL instead of your file.
I Hope this will help you
Jerome Wagner
To your question that getJSON will only alow server specific files the answer is no, it will allow file with JSON format as well also try using your code by removing the base tag for a while and see if it works
精彩评论