📌  相关文章
📜  已被 CORS 策略阻止:预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段内容类型. - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:37.158000             🧑  作者: Mango

代码示例4
var dataToSend = ' {"firstname": "' + form.vals().FirstName + '","lastname": "' + form.vals().LastName + '","email": "' + form.vals().Email + '"}';
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://exampleurl');
xhr.setRequestHeader('Content-type','application/json');
xhr.send(dataToSend);
xhr.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    console.log(this.responseText);
  }
};



xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("Access-Control-Allow-Credentials", "true");
xhr.setRequestHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
xhr.setRequestHeader("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers");