views:

97

answers:

4

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'.

A: 

Hello,

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

Jerome WAGNER
A: 

@Jerome WAGNER But i get the same result if i give it the full URL:

http://dl.dropbox.com/u/3595000/repsychal/poems/10/0512-g2g/good.json

and i have loaded from that base an img

gheil.apl
A: 

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

sushil bharwani
A: 

@Jerome WAGNER & @sushil bharwani

Ah! When i skip JSbin altogether and work directly in that directory using no base statements ... it works!

Thanks!

gheil.apl