来自不同端口的Ember ajax DELETE调用获取“;否';访问控制允许原点';标题出现在请求的资源上;
我有一个余烬应用程序,我正在尝试从组件(发送到路由)的“单击”上执行删除请求。服务器位于与用户界面不同的端口上 这是路由上的ajax请求:来自不同端口的Ember ajax DELETE调用获取“;否';访问控制允许原点';标题出现在请求的资源上;,ajax,ember.js,http-headers,cors,Ajax,Ember.js,Http Headers,Cors,我有一个余烬应用程序,我正在尝试从组件(发送到路由)的“单击”上执行删除请求。服务器位于与用户界面不同的端口上 这是路由上的ajax请求: deleteAlert(alert) { let self = this; Ember.$.ajax({ url: 'http://example.com:4320/data/alerts/' + alert.id, type:
deleteAlert(alert) {
let self = this;
Ember.$.ajax({
url: 'http://example.com:4320/data/alerts/' + alert.id,
type: 'DELETE',
beforeSend: function(request)
{
request.setRequestHeader("Access-Control-Allow-Origin","example.com:4301");
request.setRequestHeader("Access-Control-Allow-Methods","GET,POST,OPTIONS,PATCH,DELETE,PUT");
},
success: function (response) {
if(response.status==='Success!') {
Ember.Logger.log(response);
}
},
error: function(jqXHR, textStatus, errorThrown) {
Ember.Logger.error(textStatus, errorThrown, jqXHR);
}
});
但是,我得到以下错误:
XMLHttpRequest cannot load http://example.com:4320/data/alerts/252. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com:4301' is therefore not allowed access. The response had HTTP status code 404.
我还尝试将“*”添加到“Access Control Allow Origin”头中,并以以下方式定义头(在beforeSend函数之外):
同样的错误
这是需要在服务器端修复的问题吗?我对POST或GET请求没有问题,只是到目前为止删除了
感谢您的帮助 我认为这是余烬的问题,因为我对其他方法(GET、POST)没有问题。我只是将API方法更改为POST,这样使用它没有任何问题。这可能不是最好的解决方案,更多的是一种变通方法。 我确信,如果我使用了灰烬数据,灰烬将不会有删除调用的问题
request.setRequestHeader("Access-Control-Allow-Origin", "example.com:4301");
request.setRequestHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PATCH,DELETE,PUT");
这些标题不适用于客户端!您的服务器需要设置这些标头
将这些权限添加到api服务器。(在example.com:4320上提供)不同的港口意味着不同的产地,这就是它抱怨的原因。这确实是您需要在服务器端修复的问题,请尝试在上查看资源。
request.setRequestHeader("Access-Control-Allow-Origin", "example.com:4301");
request.setRequestHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS,PATCH,DELETE,PUT");