Javascript XMLHttpRequest返回控制台错误
我正在尝试从java后端到javascript前端获取一个数组。当我尝试获取该数组时,我得到一个错误,该错误表示:“localhost:4242/decks:跨源请求仅支持协议方案:http、data、chrome、chrome扩展、https。localhost:4242/decks:跨源请求仅支持协议方案:http、data、chrome、chrome扩展、https。”Javascript XMLHttpRequest返回控制台错误,javascript,java,xmlhttprequest,httprequest,Javascript,Java,Xmlhttprequest,Httprequest,我正在尝试从java后端到javascript前端获取一个数组。当我尝试获取该数组时,我得到一个错误,该错误表示:“localhost:4242/decks:跨源请求仅支持协议方案:http、data、chrome、chrome扩展、https。localhost:4242/decks:跨源请求仅支持协议方案:http、data、chrome、chrome扩展、https。” 有人愿意帮助我吗?通过xampp或任何其他Web服务器打开文件,而不是直接在浏览器中打开。我从Intellij Idea
有人愿意帮助我吗?通过xampp或任何其他Web服务器打开文件,而不是直接在浏览器中打开。我从Intellij Idea启动项目,并让wampp运行数据库
function httpGetAsync(theUrl, callback) {
let xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
};
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
function getDeck() {
httpGetAsync('localhost:4242/decks', function (response) {
response.forEach(function (deckName) {
console.log(deckName);
});
});
}