2016-08-04 19 views
0

我有一个站点托管在https://上,我想从该站点获取显示共享属性的网站数据。返回数据的网址是:无法使用XMLHttpRequest()从http站点检索数据https()

http://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191

我已经发展到获取数据的代码如下:

function GetSharesUpdate(){ 
    // makeing AJAX calls to the web service for getting the share update  
    var xhr = new XMLHttpRequest(); // Set up xhr request 
    xhr.open("GET", "http://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191", true); // Open the request 
    xhr.responseType = ""; // Set the type of response expected  
    xhr.send(); 
    // Asynchronously wait for the data to return 
    xhr.onreadystatechange = function() { 
     if (xhr.readyState == xhr.DONE) { 
      var tempoutput = xhr.responseXML; 
      alert(tempoutput); 
     } 
    } 
    // Report errors if they happen 
    xhr.addEventListener("error", function (e) { 
     console.error("Error: " + e + " Could not load url."); 
    }, false);  
} 

我收到的声明xhr.send();这是错误如下:

混合内容:在 'https://[SiteUrl]' 加载页面通过HTTPS, 但要求一个insecu re XMLHttpRequest端点 'http://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191'。 此请求已被阻止;内容必须通过HTTPS提供。

如果我更改URL,以https

https://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191

然后xhr.send();是没有任何错误执行,但我得到xhr.responseXML空。

我应该怎样改变我的代码才能使它工作?

+0

你的第二个url中有四个斜线('/')。那是对的吗? – FrankerZ

+0

感谢您的关注。添加帖子时出现输入错误。 –

+0

它执行没有任何错误?这不是当我运行它:* VM155 nizaqapusu.js:6 GET https://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191net :: ERR_INSECURE_RESPONSE *,当我访问的网址铬抱怨SSL证书用于不同的主机名。 – Quentin

回答

0

第一个问题是您正在对非https域执行ajax请求,但您的域已安装SSL。

第二个问题是跨域请求CORS,即使您先解决(即使您尝试来自非http域的ajax请求),您也会遇到此问题。

由于您正在从另一个网站请求数据,因此最有可能发生这种情况,除非所请求的服务器配置为为您提供请求域 要解决此问题,您需要从服务器(代理服务器)调用数据或者请求的服务器配置为允许来自您的域的请求。

查看更多 - https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS