jquery ajax body
时间: 2023-09-05 22:13:43 浏览: 65
jQuery's `$.ajax()` function allows you to send an HTTP request to a server and receive a response. The `data` parameter of the function can be used to specify the request body.
Here is an example of how to use `$.ajax()` with a request body:
```javascript
$.ajax({
url: '/example',
method: 'POST',
data: {
name: 'John',
age: 30
},
success: function(response) {
console.log(response);
},
error: function(xhr, status, error) {
console.log(error);
}
});
```
In this example, we are making a `POST` request to the `/example` endpoint with a JSON request body containing a `name` and an `age` property. The `success` function will be called if the request is successful, and the `error` function will be called if there is an error.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)