Hi
In order to build a weather prediction page, I was thinking to write
down a Javascript (on the client). This javascript should contact a
server (www.live.com) in ordert to extract the weather forecast.
In summary, I want a javascript based on the html client (internet
Explorer), creating a connection and extractign the data.
This sounds simple but for whatever reason, I cannot manage to extract
any data of this XML page.
Perhaps can you help me?
This code you can past it, as a document by it s own and test it and
complete it for your own pages (the server is ready to answer you).
thanks
<script language="javascript">
<!--
// Server pages - Parameters.
// URL = <Debut>+CodeVille+<Fin>
var Debut =
"http://www.live.com/cfw/weatherdata.aspx?wealocations=fr:";
var Fin = "&weadegreetype=C&culture=fr-fr&rand=0.0";
// Objects initialisation
function Weather(code)
{
//Path
this.Code = code; //town code (key)
this.LocationName = null; // Full name of the town
this.URL = null; //path for icons
this.ImageRelativeURL = null; // second part of the path
//Weather of the current day
this.CurrentTemperature = null;
this.Skycode = null; //icon
this.SkyText = null; //description
this.Date = null; //date
this.Day = null; // day of the week
this.Time = null; // time
}
// LThis is the function which has the problem
Weather.prototype.GetData = function()
{
// Object creation
var xmlData = new ActiveXObject("Microsoft.XMLDOM");
xmlData.async=false;
// URL
var URL = Debut + this.Code + Fin;
// Check the URL
alert(URL);
// Connection to the XMLwebpage
xmlData.load(URL);
// Check the connection by displaying any data
alert(xmlData.documentElement.childNodes(1).text); // <---- Here
is the error. I tryed with and without 'documentElement', but this does
not work
//read data...
alert(xmlData.root.children.item("weatherdata"));
}
// Strasbourg is the town I want to have. initialisation of the Data
var Strasbourg = new Weather("FRm_Strasbourg");
// Strasbourg object receive the data.
Strasbourg.GetData();
-->
</script>