Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 26th, 2006, 03:12 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default refresh a dynamic site

Hallo,

I am having a site, which gets the weather information of 4 cities via an XML Data. I have already done its XSLT via JavaScript it works fine but when I try to write a JavaScript refresh function I am getting an error like
document.getElementById(..)is nuill or not an object. So what should I do?

Here is my Javascript Code Chunk:

var xslProc;
var day = "1";
var wmo = "abcde";

function City(day1,wmo1){
this.day = day1;
this.wmo = wmo1;
xmlPath= "httpfoo.bar&WMO="+wmo1+"&foo.bar";
initWeather();

}

function Day(day1){
this.day = day1;
initWeather();

}
function loadXMLDoc(xmlDocURL) {
srcTree = new ActiveXObject("Msxml2.DOMDocument.3.0");
srcTree.async = false;
srcTree.load(xmlDocURL);
return srcTree;
}
function loadXSLDoc(xslDocURL) {
xsltTree = new ActiveXObject("Msxml2.XSLTemplate.3.0");
xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.3.0" );
xslDoc.async = false;
xslDoc.load(xslDocURL);
xsltTree.stylesheet = xslDoc;
return xslDoc;

}
function generateHTML(xmlTree,xslTree) {
xslProc = xsltTree.createProcessor();
xslProc.addParameter("day",day);
xslProc.addParameter("wmo", wmo);
xslProc.input = xmlTree;
xslProc.transform();
html = xslProc.output;
return html;
}

// PATH TO THE XML / XSL DOCs
var xmlPath= "http://foo.bar&WMO="+wmo+"&foo.bar";
var xslPath= "weather_city_day.xsl";

function initWeather() {
xmlTree = loadXMLDoc(xmlPath);
xslTree = loadXSLDoc(xslPath);

html = generateHTML(xmlTree, xslTree);
document.getElementById("epoWeather").innerHTML = html;


}


initWeather();

Your attitude determines your altitude
__________________
Your attitude determines your altitude
 
Old May 26th, 2006, 04:25 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

It looks like you are calling the initWeather() method before the page has finished loading, try moving the method call to the onload event...
Code:
window.onload = initWeather;
HTH,

Chris

 
Old May 26th, 2006, 04:32 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 140
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thanks for the reply but I still have one problem. As you see from the Code there is an xmlPath variable, which changes according to the city code. When I change the city to another city it stops reloading. I have define a refresh Meta tag in HTML and it loads the site fine but this problem still occurs. How can I structure this refresh structure so that it refreshes the page according to the city code? Do you have any idea?

Your attitude determines your altitude
 
Old May 26th, 2006, 11:46 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii NEO1976!!

you are using refresh meta tag.
also initWeather() method is called.
Suppose your refresh meta tag is set to 1 mints.

initWeather() function is called onload of the page.

suppose the time elapsed between these interval is 10 seconds.
initWeather() function is retrieving data using xml http request, and it takes time around 1-2 mints(for example)
at the same time your meta tag refresh method is called when time elapsed is 1 mint and it refreshes the page.
so ,avoid meta tag refresh method,rather than periodcally call it using javascript.

Hope this will help you


Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
Refresh GridView Using Refresh Button msbsam ASP.NET 2.0 Professional 0 December 6th, 2006 05:57 AM
Dynamic XML site NeilS21 XML 1 April 18th, 2005 07:35 PM
how do i change the site icon on a geocitiies site uprocker2 HTML Code Clinic 2 March 4th, 2005 07:20 AM
Crystal Report dynamic Refresh with new parameters sumansaumya Crystal Reports 0 March 19th, 2004 01:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.