Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
24
rated 0 times [  31] [ 7]  / answers: 1 / hits: 20513  / 4 Years ago, mon, august 10, 2020, 12:00:00

I'm trying to use Axios in plain JS. I've included it from CDN. In the docs they are creating Axios object like this:
const axios = require('axios');


How can I do the same without Node with plain JS?


More From » javascript

 Answers
4

Step 1. Import Axios CDN using script tag in tag. For eg.


<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/1.2.1/axios.min.js"></script>

Step 2. Use Axios in script tag like this :-


<script>
function handleRequest() {
axios.post("url", {name: "data"}).then(function (response) {
console.log(response)
// do whatever you want if console is [object object] then stringify the response
})
}


You can surely use Axios in html file without nodeJS. Happy Coding


[#50730] Monday, July 27, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dusty

Total Points: 739
Total Questions: 97
Total Answers: 85

Location: Angola
Member since Wed, Apr 13, 2022
2 Years ago
;