在JavaScript中,提交JSON格式的数据到服务器通常有几种方法,以下是一些常见的方式:
1. 使用 `XMLHttpRequest` 对象
```javascript
var xhr = new XMLHttpRequest();
xhr.open("POST", "your-endpoint-url", true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);