Created
May 11, 2014 20:08
-
-
Save ngsmrk/d34e56b5d60f61bb9ad3 to your computer and use it in GitHub Desktop.
pebble_3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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