使用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);
}
};