CORS ... Access-Control-Allow-Origin标头问题

时间:2016-12-02 21:02:55

标签: ajax cors

我已经经历了很多SO问题来解决我的这个问题,我没有找到解决方案。实际上我正试图使用​​jQuery ajax从我的网页访问Web API。我得到了Postman的请求,但是当我在浏览器上运行时,我收到了这个错误。

XMLHttpRequest cannot load https://someotherURL.com. 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:8081' is therefore not allowed access. The response had HTTP status code 403.

以下是我的ajax请求

$.ajax({
  type: 'POST',
  url: 'https://someotherURL.com',
  headers: {
    'Authorization': 'something 7d27c292ed7ec685a5fde35217b49f3'
  },
  dataType: 'json',
  data: { "someKey": "sp0.4 " },
  contentType: 'application/json; charset=utf-8',
  success: function(data, response) {
    console.log("response", response);
    console.log("Success Data - ", data);
  },
  error: function(data, error) {
    console.log("Error - ", error);
    console.log("Error Data - ", data);
  }
});

我看到很多人说使用dataType作为jsonp会修复它,但它没有。它反而给我一个404错误。有人可以帮我吗?

0 个答案:

没有答案