Hi everyone. Just an update. Managed to get all the necessary sites
being accessed from all intranet IP's via JSONP. But they are only
fired once. Eg:

http://10.48.64.75/update.php?firstSupport=Request.JSONP.request_map.request_0&getstate=0
[very first time. Some one-time setup stuff is executed here with
firstSupport();

http://10.48.64.75/update.php?updateSupport=Request.JSONP.request_map.request_1&getstate=1
 - this url is called each time via a periodical timer (every 14s).

However, it is only called once. When investing other JSONP examples,
many point to a flickr photos example. As such i have noticed that the
request_1 changes to request_2, request_3 and so on. However my script
does not. I am curious as to why this may be occurring and would it be
a good idea to loop through an array and create a unique function for
each loop, and delay it by X amount of seconds.
eg from this:

http://10.48.64.75/update.php?updateSupport=Request.JSONP.request_map.request_1&getstate=1

to something like

http://10.48.64.75/update.php?updateSupport=Request.JSONP.request_map.request_1&getstate=1
http://10.48.64.75/update.php?updateSupport=Request.JSONP.request_map.request_2&getstate=1
http://10.48.64.75/update.php?updateSupport=Request.JSONP.request_map.request_3&getstate=1

Below is my JS code used for the entire page [apologies for the
length].


var curr;
var res;

var getSupport = function(div){
    var div2 = div.setStyles({
        display:'block',
        opacity: 0
    });
    var diddy = new Fx.Tween(div2);
    diddy.start('opacity', 1 )
    res = div; // reassign some variable ready for the fade in and out
}

var chkSupport = function(div, res2){
// Perform the nice transitions depending on the state of the JSONP
resonse
    if(res2 !== curr){
        res.fade('out').setStyles({display:'none',opacity: 0});
        if(res2 == 0){
            var div2 = $
('unavailable').setStyles({display:'block',opacity: 0});
            var diddy = new Fx.Tween($('unavailable'));
            curr = 0; res = $('unavailable');
            }
        if (res2 == 1){
            var div2 = $
('available').setStyles({display:'block',opacity: 0});
            var diddy = new Fx.Tween($('available'));
            curr = 1; res = $('available');
            }
        if (res2 == 2){
            var div2 = $
('outofhours').setStyles({display:'block',opacity: 0});
            var diddy = new Fx.Tween($('outofhours'));
            curr = 2; res = $('outofhours');
            }
        var diddy = new Fx.Tween(div2);
        diddy.start('opacity', 0, 1 );
        curr = res2;
    }
}

function firstSupport(repose){
  var response = repose.state;
 //fade in the appropriate state on the first time the page is loaded.
      if(response == 0){
                getSupport($('unavailable')); curr = 0;
        }
        if (response == 1){
                getSupport($('available')); curr = 1;
        }
            if (response == 2){
                getSupport($('outofhours')); curr = 2;
        }
    }

function updateSupport(respose){
// Each time this func is called, check the response and pass it to
the chkSupport() function
            var response = respose.state;
            if(response == 0){
                chkSupport($('unavailable'), response);
            }
            if (response == 1){
                chkSupport($('available'), response);
            }
            if (response == 2){
                chkSupport($('outofhours'), response);
            }
    }

window.addEvent("domready", function(){
    //We can use one Request object many times.
    $('appLoading').fade('out');
    log2 = $('content');
    var test = new Request.HTML({
                method: 'get',
                update: log2,
                url: 'quickstart.html',
    }).send();
    $$('#navSlide li a').addEvent('click', function(event){
        event.stop();
        togGroup(this.getParent('li'), {a: null, b: 'selected'});
          var req = new Request.HTML({
                method: 'get',
                url: this.get('href'),
                    update: log2,
            onRequest: function(){
                log2.fade('out');
                $('appLoading').fade('in');
            },
            onComplete: function(){
                $('appLoading').fade('out');
                log2.fade('in');
            },
            onFailure: function(){
                log2.empty();
                log2.set('html', '<h2>No fear, we shall fix the
problem...</h2><div class="area"><table border="0"
id="errorTable"><tr><td><img src="../images/
highlytrainedmonkeys.png"><br /><em>Courtesy of Google</em></td><td>An
error has occurred while loading this page (404).<br />As you can see,
some highly-trained educated professionals are fixing the problem.<br /
><br /> Please try again by refreshing the page now.<br/>If the
problem persists, please try again later.</div></td></tr></table> ');
                log2.fade('in');
            }
          }).send();
});
// Lovely people at IT Management said no to itsupport.company.net. So
lets IP-base it. Hooray.
    var status1 = new Request.JSONP({
        method: 'get',
        url: 'http://10.48.64.75/update.php',
        data: {getstate: 0},
        callbackKey: 'firstSupport'
    }).send();
  var status2 = new Request.JSONP({
        method: 'get',
        url: 'http://10.48.64.75/update.php',
        data: {getstate: 1},
        callbackKey: 'updateSupport',
        log: true
    });
    function checkSupport(){
    status2.send();
    }
        checkSupport.periodical(14000); //run status2.send every 14s

});


Your help has been and is very much appreciated.

Regards,

James

Reply via email to