Using jQuery with Axios to get individual Ron Swanson quotes from an API
- with each click event,
jquery
replaces the button text with a Ron Swanson quote. axios
backend gets the text string from the API.
$('#get_quote').click(function() {
axios.get("https://ron-swanson-quotes.herokuapp.com/v2/quotes")
.then(function(res) {
$('button').text(res.data);
})
.catch(function(error) {
console.log(error);
})
});
$('#get_quote').click(function() {
fetch("https://ron-swanson-quotes.herokuapp.com/v2/quotes")
.then(res => res.json())
.then((data) => {
this.friends = data
$('button').text(data);
})
});