Not able to fetch data from the weatherbit account

Hi, i am not able to fetch the details from weather bit account , as the url pesent in the website is different from the one you are teaching, as the currently present url is passing the lat and lon in the link where as in yours city is passing.
i have tries to pass the both but it is not happening.

Hi @nupur01joshi,
Sorry for the delay in response. You need not use latitude and longitude. you can change the URL as,
url = "https://api.weatherbit.io/v2.0/current?city="+city+"&key=API_KEY

Please check the code below for using the city as input.

<input id="city">
<p id="output">Default Text</p>
<button onclick = "show_temp()">Submit</button>
<script type="text/javascript">
function show_temp(){
    city = document.getElementById("city").value;
    httpRequest = new XMLHttpRequest();
    url = "https://api.weatherbit.io/v2.0/current?city="+city+"&key=API_KEY";
    httpRequest.open("GET",URL);
    httpRequest.send();
    httpRequest.onreadystatechange = function(){
        if(this.readyState==4 && this.status==200){
            user_data = JSON.parse(this.respneText);
            document.getElementById("output").innerHTML = user_data.data[0].temp;
        }
    }
}
</script>

hello,
i am facing the same problem. i have checked code many time but still its not working!


thank you

Hi @onlygajanand,
You have spelt ‘responseText’ as ‘respneText’. Please change it to ‘responseText’ and try running it.

Let me know in case you need any help.