Problems with jQuery API Get Request

Hello all.

So I currently am working on an individual project that requires an API Call. I am using jQuery to do so, and below I have pasted my code. However, I am getting the error in chrome console saying:

“XMLHttpRequest cannot load https://enthalpy-api.herokuapp.com/6H2O(l). No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://127.0.0.1:3000’ is therefore not allowed access.”

My code for requesting the API is:

        for (var i = 0; i<reactants.length; i++) {
          $.get("https://enthalpy-api.herokuapp.com/" + reactants[i], function(result) {
            numbersReactants.push(result);
            console.log(numbersReactants);
          });
        }

This is solely an excerpt of my code, my full github project can be found here

Hi njanne19,

you have to enable cors.

just add this middleware to your express app:

app.use(function(req, res, next) {
res.header(“Access-Control-Allow-Origin”, “*”);
res.header(“Access-Control-Allow-Headers”, “Origin, X-Requested-With, Content-Type, Accept”);
next();
});

like mentioned here

@simmco

Thank you! this fixed my problem