Trouble retrieving json

Trouble retrieving json
0

#1

hey guys, I’m working on the weather app and I’m trying to retrieve the city given the lat & long.

function getCity(){
  $.getJSON("http://maps.googleapis.com/maps/api/geocode/json?latlng=53.244921,-2.479539&sensor=true", function(json) {
        $("#demo").html(JSON.stringify(json));
      });
}

This site verifies the api is good for json-retrieval. However, when I test it in html body, i.e

<button onclick="getCity()">City</button>
<p id="demo"></p>

Nothing shows up in the browser :frowning:

Any ideas on what’s going on? I think I need to involve error handling somewhere but not quite sure where to do so. Thanks for the help

##EDIT: I fixed it. I had to disable my uBlock extension :expressionless:


#2

hey! I checked your code on codepen…it’s showing the json content on clicking the button.There seems no problem!


#3

Check your console for errors and make sure you have jQuery enabled ($.getJSON is a jQuery call)


#4

@Faizahmadfaiz Really? When I click the city button nothing shows up for me. Location works however.

I made the getCity function as simple as possible…

function getCity(){
    $.getJSON("http://ip-api.com/json", function(json) {
    $("#demo").html(json);
    });
}

As you can see, when I click getCity, nothing gets printed. I also tried console.log() while inside the getJSON and nothing shows up on console…


#5

$("#demo").html(JSON.stringify(json));
it will show


#6

Still nothing :frowning:
I’m gonna look into error handling to see if I can debug the issue


#7

@gouldie Yes I have jquery enabled, I think it may be an issue with the api url.


#8

Can someone explain why at times a quote will show up, but at other times nothing shows up (at least for me)? I think it’s related to my problem with the weather api


#9

hey I understand the problem! I think you are opening the codepen with https://. Open your codepen in http .It will work!


#10

@Faizahmadfaiz I finally figured it out. I’m on chrome and I’m using an adblocker called uBlock. All I had to do was disable it and the text showed up. goddamn lol.

However, when I was looking at other people’s weather apps, ublock was activated and their app still showed me the weather! So confusing…