Ciao, no il login non avviene tramite Ajax.
Il problema è che essendo le ripetute chiamate Ajax molto ravvicinate (una al secondo) le comuni operazioni più "lunghe" vengono scavalcate.
Ecco il codice della classe che usa il PeriodicalExecuter e che fa la Ajax.Request:
codice:
Live = function() {
this.nickname = '';
this.timers = new Array();
this.timers_id = new Array();
this.timer_hnd = 0;
this.start = false;
}
Live.prototype = {
start_updating : function() {
//this.timer_hnd = setInterval(this.update, 1000);
this.timer_hnd = new PeriodicalExecuter(this.update, 1);
},
add : function(idasta, data_termine, idtimer, timer_hnd) {
// Creo un array contenente i dettagli dell'asta
this.timers.push(new Array(idasta, data_termine, idtimer, timer_hnd));
// Inserisco un riferimento all'array appena creato utilizzando l'id dell'asta.
this.timers_id[idasta] = this.timers.length-1;
},
update_asta : function(dati) {
// Inserisco i dati di una singola asta nell'array "arr"
// Aggiorno l'asta
for ( var id in arr ) {
// ...
}
this.start = true;
},
update : function() {
// Se ci sono aste da controllare allora...
if ( live.timers.length && live.nickname != '' && live.nickname != undefined) {
var toUpdate = new Array();
for ( var i = 0; i < live.timers.length; i++ ) {
toUpdate.push(live.timers[i][0]); // idasta
}
if ( toUpdate.length ) {
var ids = toUpdate.toJSON();
// Effettuo la richiesta ajax
new Ajax.Request('aste.php?op=update&ids=' + ids, {
method: 'get',
onSuccess: function(e) {
// Elaboro i dati ricevuti ed aggiorno i contatori
live.update_asta(e.responseText);
}
});
}
}
},
setNickname : function(nickname) {
this.nickname = nickname;
}
};
var live = new Live();
live.start_updating();
questo codice è un file .JS che viene caricato dalla pagina web.
Nella pagina ci sarà una cosa del tipo:
codice:
<html>
<body>
...
<script type="text/javascript">
var my_timer_1 = new cbCounter(...);
live.add('1', 'June 10, 2009 15:00:00', 'div_id_1', my_timer_1);
</script>
...
<script type="text/javascript">
var my_timer_2 = new cbCounter(...);
live.add('2', 'June 15, 2009 15:00:00', 'div_id_2', my_timer_2);
</script>
</body>
<html>
ora finchè clicco su link normali tutto bene, ma se provo a fare un login o un logout ho dei problemi. Credo perchè ci mettono un po più di tempo ed entra in funzione la nuova richiesta ajax che blocca e scavalca il tentativo di login/logout.