Skip to content

Instantly share code, notes, and snippets.

@ngsmrk
Created May 11, 2014 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngsmrk/d34e56b5d60f61bb9ad3 to your computer and use it in GitHub Desktop.
Save ngsmrk/d34e56b5d60f61bb9ad3 to your computer and use it in GitHub Desktop.
pebble_3
function fetch_random_word() {
var req = new XMLHttpRequest();
req.open('GET', 'http://thesaurus-rex.herokuapp.com/random_word/', true);
req.onload = function (e) {
var status = req.status;
var readyState = req.readyState;
console.log("Status: " + status + ", state: " + readyState);
if (req.readyState == 4 && req.status == 200) {
responseText = req.responseText;
console.log(responseText);
var response = JSON.parse(req.responseText);
var theWord = response.word;
console.log(theWord);
Pebble.sendAppMessage({"word": theWord});
} else {
console.log("Error");
Pebble.sendAppMessage({"word": "Not Found"});
}
};
req.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment