Implement the random generator of famous quotes Based on JQuery and AJAX, jqueryajax

Source: Internet
Author: User
Tags random quote generator

Implement the random generator of famous quotes Based on JQuery and AJAX, jqueryajax

This is a small application I made when I first got started with AJAX. The main functions are as follows:

1. click the button to randomly generate a famous saying and its author name. If there is no author name, "Unknown" is displayed ".
2. click the button to share the famous saying on Twitter or Weibo.

HTML:

<div class="container-fluid text-center">  

JQuery:

$(document).ready(function() {  var quote, author;   function getNewQuote() {   $.ajax({    type: "get",    url: "http://api.forismatic.com/api/1.0/",    jsonp: 'jsonp',    dataType: 'jsonp',    data: {     method: 'getQuote',     lang: 'en',     format: 'jsonp'    },    success: function(response) {     quote = response.quoteText;     author = response.quoteAuthor;     $('.quote').text('\"' + quote + '\"');     if (author) {      $('.author').text('by ' + author);     } else {      $('.author').text('by Unknown');     }    }   });  }   getNewQuote();   $('#change').on('click',  function(event) {   event.preventDefault();   getNewQuote();  });   $('#tweet').on('click',  function(event) {   event.preventDefault();   window.open('http://twitter.com/intent/tweet?text=' + encodeURIComponent(quote + ' by ' + author));  });   $('#weibo').on('click',  function(event) {   event.preventDefault();   window.open('http://v.t.sina.com.cn/share/share.php?title=' + encodeURIComponent(quote + ' by ' + author));  }) }); 

* Forismatic APIs can get famous quotes, but only the English and Russian versions... but there are also a lot of similar APIs in Chinese, and the implementation principle is similar.

Here is the DEMO. Welcome to FORK: Random Quote Generator.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.