Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Help with Javascript

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
tjaliwalpa
Posts: 293
Joined: Sun 18 Apr 2010 9:47 am
Weather Station: Davis VP2
Operating System: Linux Lite Ubuntu 16.04
Location: Karoonda, SA
Contact:

Help with Javascript

Post by tjaliwalpa »

I use js to update my current data webpage, some data on for today, on my iphone pages and also a banner on my website from the realtime.txt.

Is there some way to eliminate the garbage that occurs when the data is not available to the js. It i s easy to define the initial message before the data is read, but on the second and subsequent rereads, if the data is not read I get all sorts of messages including "undefined", "found", "undefinedthis".

Any ideas how to either get it to display previous data, waiting, unavailable or revert to previous data :?:
Bob
User avatar
mcrossley
Posts: 14388
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Help with Javascript

Post by mcrossley »

Well, there are lots of techniques, depends on the situation.

A general catch for 'undefined' would be:

Code: Select all

var a = <something>;
if (a==undefined){
  a = "Missing data";
}
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: Help with Javascript

Post by beteljuice »

JavaScript banner ?

Anyways - this is symptomatic of realtime.txt being uploaded whilst your other scripts are calling it.

If your server supports it try the 'rename' option in ftp. (if it isn't supported it won't update).

It sounds like you have three (or more) scripts that you would need to modify (double check what is already there) to be able to ignore an incomplete / corrupt file.
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
mcrossley
Posts: 14388
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Help with Javascript

Post by mcrossley »

If you are processing realtime.txt, presumably you are splitting into an array? If so check the array length before going any futher, if it is different than expected, retry the fetch from the website.

Code: Select all

 pseudo code
var array = objXML.responseText.split(" ");
if (array.length != expected_number_of_data_items>){
  call_function_to_restart_fetch();
}else{
  process_realtime_data();
}
Post Reply