我有 "No 'Access-Control-Allow-Origin' header is present ." 谁能帮我把它转换成 POST 类型的 JSONP?
I am having "No 'Access-Control-Allow-Origin' header is present ." Can anyone help me convert it to JSONP with the POST type?
我知道我需要将其更改为 JSONP,但 CORS 错误仍然存在。这是代码。 baseUrl 是 var baseUrl = "https://api.api.ai/v1/";
$.ajax({
type: "POST",
url: baseUrl + "query?v=20150910",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken
},
data: JSON.stringify({
query: input,
lang: "en",
sessionId: "mysessionid"
}),
success: function(data) {
//processResponse(data);
this.text = data.result.fulfillment.speech;
// console.log("success finally");
// console.log(this.text);
verify(data);
//return data;
// return text.result.fulfillment.speech;
},
error: function() {
//processResponse("Internal Server Error");
text = "Internal Server Error";
// console.log("Failllllllllllll");
}
});
我不确定。但就我而言,它很容易通过添加来解决
{ 'Access-Control-Allow-Origin': '*' } 在服务器端的响应头中。
我知道我需要将其更改为 JSONP,但 CORS 错误仍然存在。这是代码。 baseUrl 是 var baseUrl = "https://api.api.ai/v1/";
$.ajax({
type: "POST",
url: baseUrl + "query?v=20150910",
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": "Bearer " + accessToken
},
data: JSON.stringify({
query: input,
lang: "en",
sessionId: "mysessionid"
}),
success: function(data) {
//processResponse(data);
this.text = data.result.fulfillment.speech;
// console.log("success finally");
// console.log(this.text);
verify(data);
//return data;
// return text.result.fulfillment.speech;
},
error: function() {
//processResponse("Internal Server Error");
text = "Internal Server Error";
// console.log("Failllllllllllll");
}
});
我不确定。但就我而言,它很容易通过添加来解决 { 'Access-Control-Allow-Origin': '*' } 在服务器端的响应头中。