Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,45 @@ $(document).ready(function(){
function updateRec() {

}
function provideJoke(){
function provideJoke()
{

function loadJSON(path, success, error)
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState === XMLHttpRequest.DONE)
{
if (xhr.status === 200) {
if (success)
success(JSON.parse(xhr.responseText));
}
else
{
if (error)
error(xhr);
}
}
};
xhr.open("GET", path, true);
xhr.send();
}

loadJSON('https://08ad1pao69.execute-api.us-east-1.amazonaws.com/dev/random_joke',
function(data) {
console.log(data.setup)
console.log(data.punchline)
document.getElementById("joke").innerHTML = data.setup;
document.getElementById("joke-answer").innerHTML = data.punchline;

},
function(xhr) {
console.error(xhr);
}
);


// Complete the execution of this function to return a joke
// You may use APIs like http://api.icndb.com/jokes/random
};
Expand Down Expand Up @@ -723,4 +761,4 @@ $(document).ready(function(){
buttons[i].addEventListener('click', remove);
};
}
});
});