Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » GitHub Status API
- CatsUnited
- Scratcher
1000+ posts
GitHub Status API
Post Removed
Last edited by CatsUnited (Oct. 30, 2015 00:00:43)
bottom text
- Firedrake969
- Scratcher
1000+ posts
GitHub Status API
You can't put HTML in a form's action.
'17 rickoid
bf97b44a7fbd33db070f6ade2b7dc549
- ChocolatePi
- Scratcher
1000+ posts
GitHub Status API
you mean javascript, right? You can't put HTML in a form's action.
- savaka
- Scratcher
1000+ posts
GitHub Status API
He didn't, that's JS You can't put HTML in a form's action.
- savaka
- Scratcher
1000+ posts
GitHub Status API
And it doesn't work for me (and I just wanted <button> instead of a form)<form action=" function apiStatus(data) { console.log(data.status); }"> <input type="submit" content="Check Github Status"></input> <script src="https://status.github.com/api/status.json?callback=apiStatus"> </form>
- djdolphin
- Scratcher
1000+ posts
GitHub Status API
You could do something like this to run the script on the fly:
function apiStatus(data) { alert(data.status) } var button = document.getElementById('blah') button.addEventListener('click', function() { var head = document.getElementsByTagName('head')[0] var script = document.createElement('script') script.src = 'https://status.github.com/api/status.json?callback=apiStatus' head.appendChild(script) })
Last edited by djdolphin (Oct. 29, 2015 00:10:44)
!
- Jonathan50
- Scratcher
1000+ posts
GitHub Status API
Don't have a callback parameter, then GET it with an XHR and JSON.parse() it. You could do something like this to run the script on the fly:function apiStatus(data) { alert(data.status) } var button = document.getElementById('blah') button.addEventListener('click', function() { var head = document.getElementsByTagName('head')[0] var script = document.createElement('script') script.src = 'https://status.github.com/api/status.json?callback=apiStatus' head.appendChild(script) })
Not yet a Knight of the Mu Calculus.
- jTron
- Scratcher
100+ posts
GitHub Status API
GET it with an XHR and JSON.parse() it.
button.addEventListener('click', function() { var req = new XMLHttpRequest(); req.open('GET', 'https://status.github.com/api/status.json'); req.onload = function() { if (this.status >= 200 && this.status < 400) { var data = JSON.parse(this.response); // do whatever you want at this point } }; req.send(); };
$.getJSON('https://status.github.com/api/status.json', function(data) { // hello there // yes, you, the person writing this code // every time you run this code you will feel bad about yourself // wonder why you used jQuery // and spend an hour reevaluating your life decisions. // it's okay, though, // because you will eventually realize that since you're using jQuery. // you're obviously *better* than everybody else. });
Edit: semicolons, because I've been using node.js too much lately
Edit 2: oh, I forgot the click event listener on the jQuery one. Oh well. You can just use the nifty “.click” they've got built in. lol
Last edited by jTron (Oct. 31, 2015 20:41:58)
- Discussion Forums
- » Advanced Topics
- » GitHub Status API