jqueryを使用して、いくつかのバージョンを試しましたが、すべて同じ起源の問題がありますが、それでも最下層を自分で理解しています。まったく問題はなく、完璧です。
var api = 'xxx';
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", api, true);
xmlhttp.setRequestHeader("Content-Type", "application/json");
xmlhttp.send(JSON.stringify({
"data": {
"xx": "xx"
}
}));
xmlhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
const response = JSON.parse(this.responseText);
console.log('index.html: 25 -> onreadystatechange -> ', response);
}
};