From 2d4d7afb89435702000687555a46982a48c615b4 Mon Sep 17 00:00:00 2001 From: nikitas89 Date: Tue, 10 Oct 2017 11:15:59 +0800 Subject: [PATCH] ns --- index.html | 21 +++++++++++++++++++++ ref.txt | 34 ++++++++++++++++++++++++++++++++++ script.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ script2.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 index.html create mode 100644 ref.txt create mode 100644 script.js create mode 100644 script2.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..04916a8 --- /dev/null +++ b/index.html @@ -0,0 +1,21 @@ + + + + + + + + + +

Quotes

+
Other stuff
+ + + + + + + + + + diff --git a/ref.txt b/ref.txt new file mode 100644 index 0000000..b5903bb --- /dev/null +++ b/ref.txt @@ -0,0 +1,34 @@ +HTTP/1.1 200 OK +Connection: keep-alive +Content-Length: 1257 +Content-Type: application/json +Date: Mon, 09 Oct 2017 08:16:43 GMT +Server: Mashape/5.0.6 + + +[ + { + "quote": "Go ahead, make my day.", + "author": "Sudden Impact", + "category": "Movies" + }, + { + "quote": "All right, Mr. DeMille, I'm ready for my close-up.", + "author": "Sunset Blvd.", + "category": "Movies" + }, + { + "quote": "Show me the money!", + "author": "Jerry Maguire", + "category": "Movies" + }, + { + "quote": "If you build it, he will come.", + "author": "Field of Dreams", + "category": "Movies" + }, + { + "quote": "I see dead people.", + "author": "The Sixth Sense", + "category": "Movies" + }, diff --git a/script.js b/script.js new file mode 100644 index 0000000..961a108 --- /dev/null +++ b/script.js @@ -0,0 +1,47 @@ +$(function() { + var url = 'https://andruxnet-random-famous-quotes.p.mashape.com/?cat=movies&count=3' + var myHeaders = new Headers({ + 'X-Mashape-Key': 'GhlVH0tapJmshXdUM8M5oCgL2vG0p1nFlhrjsnuUkb3fyGMux9', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': 'application/json' + }); + //fix this. + var myInit = { + method: 'POST', + headers: myHeaders + } + var apiCall = fetch(url, myInit) + + apiCall + .then((response) => { + // console.log(response.json()) //also async + return response.json() + }) + .then(writeJoke) + .catch((err) => { + console.log(err); + }) + + function writeJoke(jokes) { + var $quotes = $('#quotes') + var $body = $('body') + var $newULList = $('