Web Request Failing (Calculator Project for Front End Library Projects)

Web Request Failing (Calculator Project for Front End Library Projects)
0

#1

Calculator Project Codepen

So I’m attempting to work in an add-on to my calculator project. I would like to have a little text area where a user can enter a mathematical expression or generic question, and get the Wolfram Alpha Knowledge Engine short answer thrown up in the display.

Everything seemed to be going fairly smoothly. Grabbed an API ID and all the needed info for a JQuery AJAX request for the JSON data (I think…). However the request keeps failing and I get a few error messages in the web dev console:

  • Failed to load https://api.wolframalpha.com/v2/query?appid=ITSA-SECRETK&format=plaintext&output=json&input=have%20a%20question?: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access. jquery.min.js:4

  • Cross-Origin Read Blocking (CORB) blocked cross-origin response https://api.wolframalpha.com/v2/query?appid=ITSA-SECRET&format=plaintext&output=json&input=have%20a%20question? with MIME type text/plain. See https://www.chromestatus.com/feature/5629709824032768 for more details.

I’ve tried using the XMLHttpRequest object for this task and seem to get about the same result. I don’t think I know enough about web requests yet to work this out myself. Is there a way around this issue?

I know there is a module they’ve made for nodeJS integration for API calls, but I was kind of hoping to keep this on codepen for now if possible.


#2

Are you sure Wolfram supports client-side requests? As far as I can see it doesn’t, so you can’t do what you’re trying to do (it just won’t allow the request as it needs to be backend, not called from JS on frontend). But they may have changed the API, I might have just missed something in the docs


#3

Thanks! I am not sure actually. Maybe going through the API/microservice cert first would be a good choice on my part so I have a better understanding of this. I just assumed that because I could correctly resolve the request by pointing my browser at the appropriate URL that I should be able to do so with requests in my script as well.