Skip to content

Instantly share code, notes, and snippets.

@liuxiaomingskm
Last active February 2, 2020 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuxiaomingskm/98249c6d65e2223765dfd0104717aa46 to your computer and use it in GitHub Desktop.
Save liuxiaomingskm/98249c6d65e2223765dfd0104717aa46 to your computer and use it in GitHub Desktop.
use Axios to replace JQery Ajax
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<button id="btn">click me!</button>
var url = 'https://opentdb.com/api.php?amount=1';
$("#btn").click(function(){
axios.get(url)
.then(function(res){
console.log(res.data.results[0].question);
})
.catch(function(){
console.log("ERR");
})}
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment