我有一個站點託管在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
空。
我應該怎樣改變我的代碼才能使它工作?
你的第二個url中有四個斜線('/')。那是對的嗎? – FrankerZ
感謝您的關注。添加帖子時出現輸入錯誤。 –
它執行沒有任何錯誤?這不是當我運行它:* VM155 nizaqapusu.js:6 GET https://ir1.euroinvestor.com/asp/ir/xmlirmultiiso2.aspx?companyid=281191net :: ERR_INSECURE_RESPONSE *,當我訪問的網址鉻抱怨SSL證書用於不同的主機名。 – Quentin