JSFiddle - React, Tailwind, and code Playground
by mram888
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.16.2/axios.js"></script>
<button onclick="req100()">
100
</button>
<button onclick="req1()">
1
</button>
<p id="printTitle"></p>
<p id="printBody"></p>
JavaScript
function req100() {
axios.get('https://s3.eu-west-1.amazonaws.com/test.local.in/test/reports/data/39fe44e5/geoStats.json')
.then(function (response) {
//here you can do whatever you want with the data you have received.
// we print how many data are inside the response.
console.log(JSON.parse(response));
var howMany = JSON.parse(response).length;
document.getElementById("printTitle").innerHTML = 'The response contains ' + howMany + ' elements.'
})
}
function req1() {
axios.get('https://jsonplaceholder.typicode.com/posts/1')
.then(function (response) {
// we print the title and the body of the post recived
var title = response.data.title;
var body = response.data.body
document.getElementById("printTitle").innerHTML = title
document.getElementById("printBody").innerHTML = body
})
}