Reputation: 65
I'm incredibly new to Codepen and coding in general, and I'm trying to figure out how to link to a really big file in Codepen. I want to use the variable pieIsGood from my GitHub gist in my Javascript in Codepen, but I have no idea how to go about doing that.
Some lovely StackOverflow user gave me a solution that involved linking to another Codepen project, but the problem is that Codepen only allows you to store a certain amount of data, and that amount is way less than I need.
Can you help me figure out how to incorporate my gist into my Codepen project? Thanks for any help!
ignore this
Upvotes: 1
Views: 620
Reputation: 106027
Just use ajax:
const url = '//gist.githubusercontent.com/Rusty25/a18f99e0e0a2c42662cc0746b71a5f00/raw/86e4fce24116005f2748aeacdb5e94624937eb31/pi_digits.json';
fetch(url).then(response => {
response.json().then(obj => {
console.log(obj.pi.slice(0,10000));
});
});
.as-console-wrapper{min-height:100%}
.as-console-row-code{word-break:break-all}
See it on CodePen: http://codepen.io/jrunning/pen/jBjVjd?editors=0011
The above uses the Fetch API, but you can use XMLHTTPRequest or jQuery's $.ajax
or whatever you prefer.
Upvotes: 1