【发布时间】:2014-06-13 13:54:22
【问题描述】:
我正在尝试创建一个 chrome 扩展程序,并且我正在尝试从 http://api.openweathermap.org/ 站点检索此扩展程序中的天气信息。 我在清单文件中提供了必要的权限。 这是我的 JavaScript 代码。
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();
}
问题是代码没有进入任何就绪状态的块。 所以在调用 send() 函数之后就像没有发生任何事情。
有什么想法吗?
这是我的扩展清单文件权限部分。
"permissions":[
"http://api.openweathermap.org/data/*",
"geolocation"
]
【问题讨论】:
-
如果是
readystate == 4 && status !== 200呢?
标签: javascript google-chrome google-chrome-extension