如何设置Access-Control-Allow-Origin以允许 Orion Context Broker上的跨域ajax请求 ver。 0.15.0
我的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.
答案 0 :(得分:1)
当前的Orion版本(0.18.1)在响应中不包含Access-Control-Allow-Origin标头,但可能会在将来的版本中以it has been identified as a potential feature执行此操作。
目前,一种可能的解决方案是使用代理(放置在Orion和您的客户端之间)在Orion的响应中添加该标头,然后再将其传递给您的客户端。