Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > it.comp.lang.javascript > #7943 > unrolled thread

Gestione eventi ajax (ajaxStop, ajaxError etc...) non sempre funzionante.

Started byGriS <GriS@nospam.no>
First post2015-12-16 09:50 +0100
Last post2015-12-17 12:02 +0100
Articles 3 — 2 participants

Back to article view | Back to it.comp.lang.javascript


Contents

  Gestione eventi ajax (ajaxStop, ajaxError etc...) non sempre funzionante. GriS <GriS@nospam.no> - 2015-12-16 09:50 +0100
    Re: Gestione eventi ajax (ajaxStop, ajaxError etc...) non sempre funzionante. Alessandro Pellizzari <shuriken@amiran.it> - 2015-12-16 20:19 +0000
      Re: Gestione eventi ajax (ajaxStop, ajaxError etc...) non sempre funzionante. GriS <GriS@nospam.no> - 2015-12-17 12:02 +0100

#7943 — Gestione eventi ajax (ajaxStop, ajaxError etc...) non sempre funzionante.

FromGriS <GriS@nospam.no>
Date2015-12-16 09:50 +0100
SubjectGestione eventi ajax (ajaxStop, ajaxError etc...) non sempre funzionante.
Message-ID<n4r8k7$ob0$1@speranza.aioe.org>
Ciao a tutti,
ho ereditato codice fatto da altri e tra le varie cose da distemare devo 
risolvere il caso di una icona tipo "spinner" che non scompare al 
termine di chiamate ajax che o vanno in errore o hanno problemi in 
genere (sto ancora debuggando in cerca del vero motivo).

Al momento, lo spinner è gestito così:

$("#spinner").bind("ajaxSend", function() {
$(this).show();
}).bind("ajaxStop", function() {
$(this).hide();
}).bind("ajaxError", function() {
$(this).hide();
});

Sottolineando che, in alcuni casi ancora non definiti, $(this).hide(); 
non viene eseguita, sapete consigliarmi il modo migliore per gestire 
comunque tutte le casistiche di una chiamata ajax?

Grazie in anticipo

[toc] | [next] | [standalone]


#7944

FromAlessandro Pellizzari <shuriken@amiran.it>
Date2015-12-16 20:19 +0000
Message-ID<dddvasFinb3U1@mid.individual.net>
In reply to#7943
Il Wed, 16 Dec 2015 09:50:13 +0100, GriS ha scritto:

> Al momento, lo spinner è gestito così:
> 
> $("#spinner").bind("ajaxSend", function() {
> $(this).show();
> }).bind("ajaxStop", function() {
> $(this).hide();
> }).bind("ajaxError", function() {
> $(this).hide();
> });

Non ho mai usato questi eventi, ma stando alla documentazione di jQuery 
vengono lanciati su document, non su elementi del DOM. Probabilmente li 
catturi grazie al bubbling, ma non so cosa sia il this in quel caso.

Io farei così:

$(document)
  .on('ajaxStart', function() {
    $('#spinner').show();
  })
  .on('ajaxStop', function() {
    $('#spinner').hide();
  })
;

Dovrebbero bastare questi due, in teoria.

Bye.

[toc] | [prev] | [next] | [standalone]


#7945

FromGriS <GriS@nospam.no>
Date2015-12-17 12:02 +0100
Message-ID<n4u4od$56f$1@speranza.aioe.org>
In reply to#7944
Grazie per la risposta,
proverò il tuo codice anche se non ho capito, ajaxStop non credo che 
gestisca anche l'error, o sbaglio?

Grazie ancora.

Il 16/12/2015 21.19, Alessandro Pellizzari ha scritto:
> Il Wed, 16 Dec 2015 09:50:13 +0100, GriS ha scritto:
>
>> Al momento, lo spinner è gestito così:
>>
>> $("#spinner").bind("ajaxSend", function() {
>> $(this).show();
>> }).bind("ajaxStop", function() {
>> $(this).hide();
>> }).bind("ajaxError", function() {
>> $(this).hide();
>> });
>
> Non ho mai usato questi eventi, ma stando alla documentazione di jQuery
> vengono lanciati su document, non su elementi del DOM. Probabilmente li
> catturi grazie al bubbling, ma non so cosa sia il this in quel caso.
>
> Io farei così:
>
> $(document)
>    .on('ajaxStart', function() {
>      $('#spinner').show();
>    })
>    .on('ajaxStop', function() {
>      $('#spinner').hide();
>    })
> ;
>
> Dovrebbero bastare questi due, in teoria.
>
> Bye.
>

[toc] | [prev] | [standalone]


Back to top | Article view | it.comp.lang.javascript


csiph-web