From c26f30fa3e3d89d2901cdf37c0f1ff2742c1a861 Mon Sep 17 00:00:00 2001 From: Persis Ngan Date: Tue, 10 Oct 2017 15:39:27 +0800 Subject: [PATCH] commit --- index.html | 21 +++++++++++++++++++++ script.js | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 index.html create mode 100644 script.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..605d5af --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + + + + + +

Random Quote

+

New quote

+ + + + + + + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..5a7cc0f --- /dev/null +++ b/script.js @@ -0,0 +1,40 @@ +$(function () { + var url = 'https://andruxnet-random-famous-quotes.p.mashape.com/' + + // var apiCall = fetch(url, {method:'post'}, {header: xhr.setRequestHeader("X-Mashape-Key", "YOURKEY")}) + + var headerKey = new Headers() + headerKey.append('X-Mashape-Key', 'jf3BSb5fISmshQPCGNR928NR0cKqp1T8hJXjsnzqXznBkpIqIL') + + var init = {method: 'POST', + headers: headerKey} + + // console.log('api call') + // console.log(apiCall) + + var apiCall = fetch(url, init) + + apiCall + .then((response) => { // when we get a response back + // console.log('response received') + // console.log(response.json()) + + return response.json() + }) + + // .then((data) + .then(data => { + console.log('data processed and converted into json') + console.log(data) + + var $title = $('h1') + + $title.text(data.quote) + }) + + .catch((err) => { + console.loh(err) + }) +}) + + // function writeLiEveryArticle (data) {