Rohan Akut Rohan Akut -4 years ago 53
Javascript Question

Why is the API data is not loading even after using getJSON call?

I want to do a simple click button function which loads the data from openweathermap API and displays it on a button click.
I tried to use getJSON and getJSONP for the same but the data is not getting displayed.
Here is my JS code:

function clicck(){
var url="http://api.openweathermap.org/data/2.5/weather?q=pune&APPID=998ccd9a6bca814795a4815ec5ea7c89";
// document.getElementById("demo").innerHTML=url;
$.getJSONP(url,function(a){
("demo").html(JSON.stringify(a));
});
}


My HTML code for the button is :

<p id="demo"></p>
<button onclick="clicck()">kuyku
</button>


I know its a basic question but I am really stuck on it.Your help would be appreciated.

Answer Source

I tried your solution, and find problem with JSONP function. If provided solution with misspelled selector $('#demo') does not works, here the fiddle using only jQuery ajax functions.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download