[英]Chrome Extension xmlHttpRequest not working
我正在尝试创建一个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"
]
好吧,我想我自己找到了答案。 Javascript区分大小写。 我错误地将readyState
写为readystate
。
我真傻。
谢谢大家。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.