# Having problems with API/jQuery

**URL:** <https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560>\
**Category:** General\
**Created:** [February 27, 2017, 1:21am UTC](https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560 "2017-02-27T01:21:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bahnzo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bahnzo/32/163322_2.png) [@Bahnzo](https://forum.freecodecamp.org/u/Bahnzo)\
**Post date:** [February 27, 2017, 1:21am UTC](https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560/1 "2017-02-27T01:21:35Z")

</div>

Here’s my codepen: [https://codepen.io/Bahnzo/pen/KWpzjj](https://codepen.io/Bahnzo/pen/KWpzjj)

I’ve been told the alert box pops up for others, but for me, it won’t. It’s something with the $.getJSON() request. If I put a generic alert(“Pop Up!”); in the JSON call, it also won’t pop up, but if I move it outside of the call, it works fine.

I’m really stumped here. I can open the “[http://freegeoip.net/json/](http://freegeoip.net/json/)” in my browser and see the JSON data just fine, so that doesn’t seem it.

Any idea what’s going on here? I’d really like to use this site for location data.

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [February 27, 2017, 2:29am UTC](https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560/2 "2017-02-27T02:29:49Z")

</div>

When you connect to CodePen via HTTPS, you _must_ use only HTTPS connections in JavaScript. Your API is hosted via HTTP. Stick a CORS proxy on your URL and it should work fine, like `https://cors-anywhere.herokuapp.com`.

```auto
https://cors-anywhere.herokuapp.com/http://freegeoip.net/json/

```

However, if you’re trying to get location information from this API, as the name might suggest, you really ought to use the browser’s [geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation).

---

<div class="post-metadata">

**Author:** ![belcurv](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/belcurv/32/81260_2.png) [@belcurv](https://forum.freecodecamp.org/u/belcurv)\
**Post date:** [February 27, 2017, 2:49am UTC](https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560/3 "2017-02-27T02:49:01Z")

</div>

Alternatively, you can just remove the ‘s’ from ‘https’ 🙂

---

<div class="post-metadata">

**Author:** ![Bahnzo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bahnzo/32/163322_2.png) [@Bahnzo](https://forum.freecodecamp.org/u/Bahnzo)\
**Post date:** [February 27, 2017, 3:23am UTC](https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560/4 "2017-02-27T03:23:27Z")

</div>

Ok, so the https works. But this wouldn’t work when running it locally as well. Same rules apply?

But…the site also can be opened securely as well “[https://freegeoip.net/json/](https://freegeoip.net/json/)” but I tried that and wouldn’t work.

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [February 27, 2017, 3:43am UTC](https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560/5 "2017-02-27T03:43:25Z")

</div>

> [@belcurv](#):
>
> Alternatively, you can just remove the ‘s’ from ‘https’

No. Don’t do this. So many bad. Such awful.

> [@Bahnzo](#):
>
> But this wouldn’t work when running it locally as well. Same rules apply?

Yup.

> [@Bahnzo](#):
>
> But…the site also can be opened securely as well “[freegeoip.net](https://freegeoip.net/json/)” but I tried that and wouldn’t work.

I just tried it and it worked for me, but there are some reason why it might not even if you’re just using secure protocols. The browser’s native geolocation service won’t have this problem, though.

---

<div class="post-metadata">

**Author:** ![Bahnzo](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bahnzo/32/163322_2.png) [@Bahnzo](https://forum.freecodecamp.org/u/Bahnzo)\
**Post date:** [February 27, 2017, 3:55am UTC](https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560/6 "2017-02-27T03:55:32Z")

</div>

> [@PortableStick](#):
>
> The browser’s native geolocation service won’t have this problem, though.

I get that, but I’m trying to avoid having the user have to allow that. This is for the “Show the Local Weather” part of the course, and a city, state is good enough info to allow me to get weather data.

---

<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 16, 2021, 2:47pm UTC](https://forum.freecodecamp.org/t/having-problems-with-api-jquery/91560/7 "2021-01-16T14:47:55Z")

</div>


