How to make a WolframAlpha request to static Github pages?

I am trying to request tungsten to do some math for my site and then display the result. I have problems with CORS. My code is:

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); 

My mistake:

"Cross-query request blocked: a policy of the same origin prohibits reading the remote resource at http://api.wolframalpha.com/v2/query?input=sqrt(100)&appid= . (Reason: CORS 'Access-Control header -Allow-Origin 'is missing.)

I understand that on a dynamic site I could just add

 Header set Access-Control-Allow-Origin "*" 

to.htaccess

but I'm not sure how to do this on a static site. I read that Allow-Access_origin should already be present on github pages.

The second answer is here: Sharing resources on GitHub pages

2nd answer here: Is there a way to enable CORS on Github pages?

+6
source share
1 answer

If this is a small project, you can redirect your receiving requests through crossorigin.me . Otherwise, you will have to start the server itself, which requests a proxy server for wolfram alpha and sets the Access-Control-Allow Origin header header correctly. You can even deploy one of these proxies to now.sh or heroku for free or cheap. I have a similar simple github-issue-filer application that sets the header correctly and redirects the POST to the github API.

+2
source

All Articles