Reputation: 450
I'm trying to create a chrome extension and I'm trying to retrieve the weather information in this extension from the http://api.openweathermap.org/ site. I have provided the necessary permissions in the manifest file. Here is my javascript code.
function processPosition(pos)
{
document.getElementById("testDiv").innerHTML = "Position available. lat=" + pos.coords.latitude + "&lon=" + pos.coords.longitude;
v_url = "http://api.openweathermap.org/data/2.5/weather?lat=" + pos.coords.latitude + "&lon=" + pos.coords.longitude;
if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if(xmlhttp.readystate == 4 && xmlhttp.status == 200)
{
processWeatherJSON(xmlhttp.responseText);
}
else if(xmlhttp.readystate == 3)
{
document.getElementById("testDiv").innerHTML = "Downloading data";
}
else if(xmlhttp.readystate == 2)
{
document.getElementById("testDiv").innerHTML = "Send has been called";
}
else if(xmlhttp.readystate == 1)
{
document.getElementById("testDiv").innerHTML = "Ready state 1";
}
else if(xmlhttp.readystate == 0)
{
document.getElementById("testDiv").innerHTML = "Ready state 0";
}
}
xmlhttp.open("GET",v_url,true);
xmlhttp.send();
}
The problem is that the code does not enter the blocks for any of the readystates. So its like nothing has happened after the send() function was called.
Any ideas?
Here is my extension manifest file permissions section.
"permissions":[
"http://api.openweathermap.org/data/*",
"geolocation"
]
Upvotes: 1
Views: 498
Reputation: 450
Alright I guess I found the answer myself.
Javascript is case-sensitive. I wrongly wrote readyState
as readystate
.
Really silly of me.
Thanks to everyone.
Upvotes: 1