我在执行axios发布请求时遇到以下错误。但是,当我使用ajax请求时,没有问题:
该请求已被CORS策略阻止:对预检请求的响应未通过访问控制检查:所请求的资源上没有'Access-Control-Allow-Origin'标头。
Ajax请求:
Axios请求:
let payload = {
type: ["a", "b"],
category: ["a", "b"],
category: ["a", "b"],
accountNumber: "123"
};
var apiURL = this.$apiBaseURL + "/Product/ProductDetails";
$.ajax({
url: apiURL,
type: "POST",
data: { payload },
xhrFields: {
withCredentials: true
},
success: function (result) {
console.log(JSON.stringify(result));
}
});
this.$http.post(apiURL,payload,{withCredentials: true})
Content-type
标头设置为'Content-Type': 'application/x-www-form-urlencoded'
。您必须在服务器端更改设置才能解决此问题。