Author Topic: AJAX and wflash  (Read 5380 times)

0 Members and 1 Guest are viewing this topic.

Offline Curly

  • Forecaster
  • *****
  • Posts: 724
    • Michiana Weather
AJAX and wflash
« on: October 04, 2007, 06:58:44 PM »
I've been working  on a java script to produce a "Record Hi" and a "Record Low" next to the daily high/lo temp when it occurs. It gets the data from the data.txt file that is used for my banner that contains the info from a mesonet tag. Since I'm using VWS with AJAX, (thanks guys) can ajaxVWSwxf.js be modified to use the data.txt file along with the wflash files?

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 8386
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: AJAX and wflash
« Reply #1 on: October 04, 2007, 08:08:04 PM »
Sure Curly, the ajaxVWSwxf.js can be modified to pull just the data.txt file.

I'd suggest you copy the basic code from the ajaxGetUnits function (which runs once when the script loads) and rename it to ajaxGetDataTxt like this
Code: [Select]
// ------------------------------------------------------------------------------------------
//  function.. read data.txt and and decode values .. run once
// ------------------------------------------------------------------------------------------
function ajaxGetDataTxt(url) {
// read the data.txt file and set up all-time records
// This routine is run once at startup (load of page)
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);

  }
  if (x) { // got something back
    x.onreadystatechange = function() {
    try { if (x.readyState == 4 && x.status == 200) { // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE
      var data = x.responseText.split(','); // assuming comma-delimited format
// put stuff to decode your data.txt file here.
// variables as data[n] based on above split
//
// like:
//  set_ajax_obs("ajaxtemprecord",data[0]);
//


// --- end of processing data[n] values
      x.abort();

//  } // END if(wunits[0]

} // END if (x.readyState == 4 && x.status == 200)

    } // END try

    catch(e){ }  // Mike Challis added fix to fix random error: NS_ERROR_NOT_AVAILABLE

    } // END x.onreadystatechange = function() {
    x.open("GET", url, true);
    x.send(null);
// alert("did Open and send of null");
  }
 
} // end ajaxGetDataTxt function



Insert
Code: [Select]
var wflashDataTxt = './data.txt'; // relative path to data.txt file in the settings area near the top of the script, then near the bottom ot the script replace
Code: [Select]
// Start the pair of AJAX loaders .. they'll reinvoke themselves
ajaxLoaderVWSf(wflashFile + '?' + new Date().getTime());
ajaxLoaderVWSf2(wflashFile2 + '?' + new Date().getTime());
to
Code: [Select]
// Start the pair of AJAX loaders .. they'll reinvoke themselves
ajaxLoaderVWSf(wflashFile + '?' + new Date().getTime());
ajaxLoaderVWSf2(wflashFile2 + '?' + new Date().getTime());
ajaxGetDataTxt(wflashDataTxt + '?' + new Date().getTime());


That should allow you an easy way to get data.txt once, decode the values (you have to fill in those functions as shown above), and update what you'd like on the webpage.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Curly

  • Forecaster
  • *****
  • Posts: 724
    • Michiana Weather
Re: AJAX and wflash
« Reply #2 on: October 04, 2007, 10:01:23 PM »
Amazing...

I've spent nearly two weeks working on the code and the frustration level was slowly rising. I was very close to what you've posted and realized what my mistakes were. I used everything you posted and it works great!

I owe ya!  

Thanks A Bunch Ken

Curly

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 8386
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: AJAX and wflash
« Reply #3 on: October 05, 2007, 01:25:55 AM »
You're very welcome Curly.  I have to confess that I spent several days working on how to get the AJAX function to work ONCE and quit (for the fetch of the WeatherFlash config file.  Pulled my hair (and I have so little left), but the secret was to kill the transaction after I'd milked the data with the x.abort(); call -- otherwise, the status bar just kept saying 'Loading....'.  Grrrr.

I'm glad that code-reuse is available  :lol:

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

 

anything