Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 26th, 2006, 03:12 AM
Friend of Wrox
 
Join Date: May 2005
Location: Nürnberg/München, , Germany.
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
Reply With Quote
  #2 (permalink)  
Old May 26th, 2006, 04:25 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
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

Reply With Quote
  #3 (permalink)  
Old May 26th, 2006, 04:32 AM
Friend of Wrox
 
Join Date: May 2005
Location: Nürnberg/München, , Germany.
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
Reply With Quote
  #4 (permalink)  
Old May 26th, 2006, 11:46 PM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:37 AM.


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