Front end to backend
axios.get('https://example.com')
.then(response => {console.log(response.data)})
.catch(error => {console.log(error)})
Dependency array
𝕹𝖕𝖒 𝖎 𝖓𝖆𝖝𝖎𝖔𝖘
Axios.get
Faizan Imran - 29/10/2024
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Axios GET Request Example</title>
<!-- Add some CSS to style the output -->
<style>
#data {
margin-top: 20px;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Axios GET Request Example</h1>
<div id="data">Loading data...</div>
<!-- Include Axios from CDN -->
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
// Make an axios GET request
axios.get('https://jsonplaceholder.typicode.com/posts/1')
.then(response => {
// Display the data in the "data" div
document.getElementById('data').innerText = JSON.stringify(response.data, null, 2);
})
.catch(error => {
// Handle any errors
document.getElementById('data').innerText = 'Error loading data';
console.error(error);
});
</script>
</body>
</html>
Comments
Post a Comment