dfm / osrc

The Open Source Report Card
http://osrc.dfm.io
MIT License
1.03k stars 137 forks source link

Fetch JSON data using Ajax? #85

Closed henryruhs closed 10 years ago

henryruhs commented 10 years ago

Hello,

can you give an example how to fetch the JSON data using jQuery's Ajax or native Ajax? I tried JSON and JSONP, didn't work at all.

I'd like to add some of your stats to my website.

Thanks!

dfm commented 10 years ago

You haven't been terribly clear about what didn't work and this isn't really the place to ask how to write JavaScript... but...

If you're not on the dfm.io domain (hope you're not), you have to use JSONP:

<script>
function dudeface(data) {
    console.log(data);
}
</script>
<script src="http://osrc.dfm.io/dfm.json?callback=dudeface"></script>
henryruhs commented 10 years ago

Thanks DFM, thats the jQuery snip working well... maby you should put this online somewhere?

$.ajax({
    url: 'http://osrc.dfm.io/dfm.json',
    dataType: 'jsonp',
    jsonpCallback: 'dudeface'
});
function dudeface (data) {
    console.log(data);
};