html axios
时间: 2023-09-24 18:05:28 浏览: 80
axios.js(0.26.0)
5星 · 资源好评率100%
Axios is a popular JavaScript library used for making HTTP requests from the browser or Node.js. It supports various features such as handling request and response interceptors, performing async operations, and providing easy-to-use APIs for sending HTTP requests and handling responses.
To use Axios in an HTML file, you need to include the Axios library by adding the following script tag in your HTML file:
```html
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
```
Once you have included Axios, you can start using it in your JavaScript code. Here's an example of how you can make a GET request using Axios:
```javascript
axios.get('https://api.example.com/data')
.then(function (response) {
// handle success
console.log(response.data);
})
.catch(function (error) {
// handle error
console.log(error);
});
```
In this example, we call the `axios.get()` method with the URL of the API endpoint as the parameter. The `get()` method returns a promise, and we can use the `.then()` method to handle a successful response and the `.catch()` method to handle any errors that occur during the request.
阅读全文