Orion Context Broker 上没有 'Access-Control-Allow-Origin' header

No 'Access-Control-Allow-Origin' header is present on Orion Context Broker

如何设置 Access-Control-Allow-Origin 以允许 Orion Context Broker ver.0.15.0[=24 上的跨域 ajax 请求=]

我的 JS 脚本

function capture_sensor_data(){  
var contentTypeRequest = $.ajax({  
      url: 'http://x.x.x.x:1026/ngsi10/queryContext',  
      data: {
            "entities": [
                {
                    "type": "Room",
                    "isPattern": "false",
                    "id": "Room1"
                }
            ]
        },  
      type: 'POST',  
      dataType: 'json',  
      contentType: 'application/json',  
      headers: { 'X-Auth-Token' :'you_auth_token'}  
  });  

  contentTypeRequest.done(function(data){   
     console.log(data);                     
  });                 
  contentTypeRequest.fail(function(jqXHR, textStatus){     
       console.log( "DEBUG :  Ajax request failed... (" + textStatus + ' - ' + jqXHR.responseText + ")." );  
  });  
  contentTypeRequest.always(function(jqXHR, textStatus){       });  

};

回应

XMLHttpRequest cannot load http://x.x.x.x:1026/ngsi10/queryContext. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://x.x.x.x' is therefore not allowed access. The response had HTTP status code 405.

当前的 Orion 版本 (0.18.1) 在响应中不包含 Access-Control-Allow-Origin header,尽管它可能会在未来的版本中包含 it has been identified as a potential feature.[=11] =]

目前,一种可能的解决方案是使用代理(放置在 Orion 和您的客户端之间)在 Orion 的响应中添加 header,然后再将它们传递给您的客户端。