Emotion API Javascript API CORS标题'Access-Control-Allow-Origin'丢失 [英] Emotion API Javascript API CORS header 'Access-Control-Allow-Origin' missing
问题描述
我想在网络应用中使用情绪检测。我错过了什么吗? (我意识到以这种方式包含密钥是不明智的,这仅用于测试目的。)
I would like to use emotion detection in a web app. Am I missing something? (I realise it is unwise to include the key in this way, this is just for test purposes.)
我的代码是(直接来自https://dev.projectoxford.ai/docs / services /...):
My code is (straight from https://dev.projectoxford.ai/docs/services/...):
    $ .ajax({
contentType:" application / json",
       URL:" HTTPS://api.projectoxford.ai/emotion/v1.0/recognize" ;,
   &NBSP ; beforeSend:function(xhrObj){
//请求标题
         xhrObj.setRequestHeader(QUOT;内容类型","应用/ JSON");
  &NBSP ; xhrObj.setRequestHeader(" Ocp-Apim-Subscription-Key"," ********************** **");
},
type: " POST",
data:" {'url':'http:// *********** *********'}",
跨度>  dataType:" json"
      })
      .done(功能(数据){
alert(" success");
})
      .fail(function(){
alert(" error");
;});
$.ajax({
contentType: "application/json",
url: "https://api.projectoxford.ai/emotion/v1.0/recognize",
beforeSend: function(xhrObj){
// Request headers
xhrObj.setRequestHeader("Content-Type","application/json");
xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","************************");
},
type: "POST",
data: "{ 'url': 'http://********************' }",
dataType: "json"
})
.done(function(data) {
alert("success");
})
.fail(function() {
alert("error");
});
错误是:
推荐答案
此处存在同样的问题。执行示例JavaScript代码时,我得到:
Same issue here. When executing the example JavaScript code, I get:
选项https://api.projectoxford.ai/emotion/v1.0/recognize 404(未找到资源)
XMLHttpRequest无法加载https://api.projectoxford.ai/emotion/v1.0/recognize.
对预检请求的响应未通过访问控制检查:否'访问 - Control-Allow-Origin'&b;
标头出现在请求的资源上。因此,不允许来源"http:// localhost:7357"访问。
响应的HTTP状态代码为404.
OPTIONS https://api.projectoxford.ai/emotion/v1.0/recognize 404 (Resource Not Found)
XMLHttpRequest cannot load https://api.projectoxford.ai/emotion/v1.0/recognize.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin'
header is present on the requested resource. Origin 'http://localhost:7357' is therefore not allowed access.
The response had HTTP status code 404.
谢谢,
Jim。
这篇关于Emotion API Javascript API CORS标题'Access-Control-Allow-Origin'丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!