我正在尝试查询Wolfram以执行一些与我的网站相关的数学运算,然后显示结果。我遇到了CORS问题。
我的代码:
我的代码:
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", "http://api.wolframalpha.com/v2/query?input="+theUrl+"&appid=", true); // true for asynchronous
xmlHttp.send(null);
我的错误:
"跨域请求被阻止:同源策略不允许从远程资源读取 http://api.wolframalpha.com/v2/query?input=sqrt(100)&appid=。(原因:缺少CORS头 'Access-Control-Allow-Origin')。"
我知道在动态网站上可以添加以下内容:
Header set Access-Control-Allow-Origin "*"
转至 .htaccess 文件
但我不确定如何在静态网站上进行此操作。我已经阅读到 Allow-Access_origin 应该已经存在于 Github Pages 中。
第二个答案在这里:GitHub Pages 上的跨源资源共享
第二个答案在这里:有没有办法在 Github Pages 上启用 CORS?