使用https安全URL上的jQuery进行跨源资源共享问题?

时间:2017-11-05 01:19:37

标签: javascript jquery ajax get cors

我对跨站点来源请求有轻微问题。我确定这是一个简单的修复方法。

控制台错误:

XMLHttpRequest无法加载https://subdomain.example.com/social/disqus。对预检请求的响应没有通过访问控制检查:否'访问控制 - 允许 - 来源'标头出现在请求的资源上。起源' https://www.example.com'因此不允许访问。

导致问题的js脚本:

window.onload = function(){
  //jQuery AJAX GET Method on Disqus Threads
  $.ajax({
    type: 'GET',
    url: 'https://subdomain.example.com/social/disqus',
    contentType: 'application/json; charset=utf-8',

    success: function(threads) {
      var len = Object.keys(threads.response).length
      for (i = 0; i < len; i++){
        if (threads.response[i].posts == 0 || threads.response[i].posts != 1) {
          $('#' + threads.response[i].identifiers).html(threads.response[i].posts + " Comments ");
        } else {
          $('#' + threads.response[i].identifiers).html(threads.response[i].posts + " Comment ");
        }
      }
    },
    error: function() {
      console.log("Aw, snap!");
    }
  });
};

我在Apache中强制重定向 - 这可能是一个问题,但看起来CORS请求是从https://有效站点触发到另一个https://有效站点... ajax请求中的url 肯定是 https。

我想知道我是否遗漏了$.ajax的某些内容?

0 个答案:

没有答案