I have a question about a weird status I am getting while trying to access Wunderground through javascript.
When I make a call using the script below, I get an response back... the XMLHttpRequest.readyState is 4 but the XMLHttpRequest.status = 0.
//Global and init
var request;
//Weather data
var weekday;
var high;
var low;
var condition;
var pop;
function getWeather(latitude,longitude)
{
request = new XMLHttpRequest();
request.onreadystatechange = weatherStateChange;
if (typeof XDomainRequest != "undefined")
{
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
request = new XDomainRequest();
request.open("GET", "http://api.wunderground.com/api/66b1a...;
}
else
{
request.open("GET", "http://api.wunderground.com/api/66b1a..., true);
}
request.send(null);
}
function weatherStateChange()
{
if(request.readyState == 4 && request.status == 200)
{
alert('recieved weather data');
}
alert(request.getAllResponseHeaders());
}
Do I need to include any additional headers in my request? Maybe change the Content-Type? I have used a very similar script to access my own webservice and it works wonderfully. Any ideas?
EDIT: The post didn't show the full URL i used here it is
api.wunderground.com/api/66b1afdaedd9ea4c/forecast/q/"+latitude+","+longitude+".xml
When I make a call using the script below, I get an response back... the XMLHttpRequest.readyState is 4 but the XMLHttpRequest.status = 0.
//Global and init
var request;
//Weather data
var weekday;
var high;
var low;
var condition;
var pop;
function getWeather(latitude,longitude)
{
request = new XMLHttpRequest();
request.onreadystatechange = weatherStateChange;
if (typeof XDomainRequest != "undefined")
{
// XDomainRequest only exists in IE, and is IE's way of making CORS requests.
request = new XDomainRequest();
request.open("GET", "http://api.wunderground.com/api/66b1a...;
}
else
{
request.open("GET", "http://api.wunderground.com/api/66b1a..., true);
}
request.send(null);
}
function weatherStateChange()
{
if(request.readyState == 4 && request.status == 200)
{
alert('recieved weather data');
}
alert(request.getAllResponseHeaders());
}
Do I need to include any additional headers in my request? Maybe change the Content-Type? I have used a very similar script to access my own webservice and it works wonderfully. Any ideas?
EDIT: The post didn't show the full URL i used here it is
api.wunderground.com/api/66b1afdaedd9ea4c/forecast/q/"+latitude+","+longitude+".xml