A Pen by liuxiaomingskm on CodePen.
Last active
February 2, 2020 00:49
-
-
Save liuxiaomingskm/98249c6d65e2223765dfd0104717aa46 to your computer and use it in GitHub Desktop.
use Axios to replace JQery Ajax
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<button id="btn">click me!</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | |
})} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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