Javascript 通过HTTPS调用XMLHttpRequest时加载内容失败
假设我有下面的URLJavascript 通过HTTPS调用XMLHttpRequest时加载内容失败,javascript,jquery,ajax,xmlhttprequest,Javascript,Jquery,Ajax,Xmlhttprequest,假设我有下面的URL https://www.somthing.com/shop/AjaxLogonForm?catalogId=10051&langId=-1&storeId=10151 现在我有了下面的JavaScript来获取内容: var req = new XMLHttpRequest(); req.open("GET",document.location.origin,false); req.send(); 在执行上述代码时,它会抛出类似“未能执行XMLHttpR
https://www.somthing.com/shop/AjaxLogonForm?catalogId=10051&langId=-1&storeId=10151
现在我有了下面的JavaScript来获取内容:
var req = new XMLHttpRequest();
req.open("GET",document.location.origin,false);
req.send();
在执行上述代码时,它会抛出类似“未能执行XMLHttpRequest上的发送”这样的执行选项。现在,如果我更改open()如下所示
然后抛出混合内容错误。
请建议在这种情况下如何获取数据。试试这个
var xmlhttp = getXmlHttp();
xmlhttp.open('GET', document.location, true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
var responseHeaders = xmlhttp.getAllResponseHeaders();
}
}
};
xmlhttp.send(null);
当通过https加载页面,并通过http加载js文件时,会出现混合内容问题。你想得到什么网址?因为这个请求只会到达。js在哪里?如果它在不同的域中,那么您将被CORS阻止。我想获得请求的响应头..JS位于该URL上。
var xmlhttp = getXmlHttp();
xmlhttp.open('GET', document.location, true);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
var responseHeaders = xmlhttp.getAllResponseHeaders();
}
}
};
xmlhttp.send(null);