# Problems with jQuery API Get Request

**URL:** <https://forum.freecodecamp.org/t/problems-with-jquery-api-get-request/114665>\
**Category:** General\
**Created:** [May 11, 2017, 5:21pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery-api-get-request/114665 "2017-05-11T17:21:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![njanne19](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/njanne19/32/29538_2.png) [@njanne19](https://forum.freecodecamp.org/u/njanne19)\
**Post date:** [May 11, 2017, 5:21pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery-api-get-request/114665/1 "2017-05-11T17:21:57Z")

</div>

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)](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](http://127.0.0.1:3000)’ is therefore not allowed access.”

My code for requesting the API is:

```auto
        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](https://github.com/njanne19/enthalpy-calculator-p2)

---

<div class="post-metadata">

**Author:** ![simmco](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@simmco](https://forum.freecodecamp.org/u/simmco)\
**Post date:** [May 11, 2017, 7:11pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery-api-get-request/114665/2 "2017-05-11T19:11:31Z")

</div>

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](https://enable-cors.org/server_expressjs.html)

---

<div class="post-metadata">

**Author:** ![njanne19](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/njanne19/32/29538_2.png) [@njanne19](https://forum.freecodecamp.org/u/njanne19)\
**Post date:** [May 12, 2017, 1:24pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery-api-get-request/114665/3 "2017-05-12T13:24:59Z")

</div>

@simmco

Thank you! this fixed my problem

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 17, 2021, 8:54pm UTC](https://forum.freecodecamp.org/t/problems-with-jquery-api-get-request/114665/4 "2021-01-17T20:54:53Z")

</div>

Closed on January 17, 2021, 8:54pm UTC


