Discuss Scratch

savaka
Scratcher
1000+ posts

GitHub Status API

So how do I use this?
I want to make a button using the <button> tag that will alert the status (good, minor, or major) when you click it.
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

Firedrake969 wrote:

You can't put HTML in a form's action.
you mean javascript, right?
savaka
Scratcher
1000+ posts

GitHub Status API

Firedrake969 wrote:

You can't put HTML in a form's action.
He didn't, that's JS
savaka
Scratcher
1000+ posts

GitHub Status API

CatsUnited wrote:

<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>
And it doesn't work for me (and I just wanted <button> instead of a 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

djdolphin wrote:

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)
})
Don't have a callback parameter, then GET it with an XHR and JSON.parse() it.

Not yet a Knight of the Mu Calculus.
jTron
Scratcher
100+ posts

GitHub Status API

Jonathan50 wrote:

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();
};
Or you could be lame and use jQuery.
$.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.
});
I don't know what people are going on about when they say jQuery helps you write less code. That was the exact same amount of lines.

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)


clipd • osx clipboard manager and history

;

Powered by DjangoBB