-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript1.js
More file actions
37 lines (29 loc) · 942 Bytes
/
script1.js
File metadata and controls
37 lines (29 loc) · 942 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$(document).ready(function(){
var $quote = $('#quote');
var $author = $('#author');
function ajaxCall() {
$.ajax({
url: "https://api.forismatic.com/api/1.0/",
jsonp: "jsonp",
dataType: "jsonp",
data: {
method: "getQuote",
lang: "en",
format: "jsonp"
}
})
.done(update)
.fail(handleErr);
}
function update(response) {
$quote.text(response.quoteText);
$author.text(response.quoteAuthor);
// set twitter url
$("#tweet-quote").attr('href','https://twitter.com/intent/tweet?text=' + response.quoteText + " " + response.quoteAuthor + '&hashtags=quotes,famous quotes') ;
}
function handleErr(jqxhr, textStatus, err) {
console.log("Request Failed: " + textStatus + ", " + err);
}
ajaxCall();
$('#new-quote').on('click', ajaxCall);
});