Skip to content

Instantly share code, notes, and snippets.

@ngsmrk
Created May 11, 2014 20:08
Show Gist options
  • Select an option

  • Save ngsmrk/d34e56b5d60f61bb9ad3 to your computer and use it in GitHub Desktop.

Select an option

Save ngsmrk/d34e56b5d60f61bb9ad3 to your computer and use it in GitHub Desktop.

Revisions

  1. ngsmrk created this gist May 11, 2014.
    27 changes: 27 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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);
    }