如何设置 Access-Control-Allow-Origin 以允许Orion Context Broker版本上的跨域 ajax 请求。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.