Een raar probleem, waar ik niet uit kom 
De situatie in stappen.
1. var busy = true;
2. Producten ophalen
3. location.hash = hash;
4. var busy = false;
Op enkele plekken busy bekeken:
1. Before callback, busy = true;
2. Ajax request met parameters.
3. Done callback, busy = false;
Dan bij 4 krijgen we een hashchange, terwijl ik al voor busy = false de location.hash wijzig!
De versimpelde code:
De functie get_products() word aangeroepen bij het veranderen van de opties, of als er geklikt word op volgende/vorige knoppen van de browser 'hashChange'.
Heeft iemand een idee waarom hij niks doet met deze volgorde?
De situatie in stappen.
1. var busy = true;
2. Producten ophalen
3. location.hash = hash;
4. var busy = false;
Op enkele plekken busy bekeken:
1. Before ajax, busy: true 2. Ajax request! 3. After ajax, busy: false 4. Hashchange, busy: false 5. Before ajax, busy: true 6. Ajax request! 7. After ajax, busy: false
1. Before callback, busy = true;
2. Ajax request met parameters.
3. Done callback, busy = false;
Dan bij 4 krijgen we een hashchange, terwijl ik al voor busy = false de location.hash wijzig!
De versimpelde code:
JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| var busy = false; (function($){ $.fn.get_products = function(args){ var target = $(this); $.ajax({ type: 'POST', url: ajaxurl, data: data, dataType: 'json', beforeSend: function (xhr) { busy = true; console.log('Before ajax, busy: '+busy); } }).done(function (response) { console.log('Ajax request!'); if (response.status === "OK") { if (response.data.hash) { location.hash = "filter:"+response.data.hash; } else if (location.hash) { location.hash = ''; } // [...] Andere shizzle target.html(response.data.html); } else { // Spit out response for debugging console.log(response); } busy = false; console.log('After ajax, busy: '+busy); }); }; })(jQuery); |
De functie get_products() word aangeroepen bij het veranderen van de opties, of als er geklikt word op volgende/vorige knoppen van de browser 'hashChange'.
JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| // Detect a hash change, browser next of prev buttons $(window).hashchange(function(){ console.log('Hashchange, busy: '+busy); if (!busy) { // Check is a hash is present if (location.hash) { // Get products by hash productListing.get_products({ hash: location.hash }); } else { // Get products productListing.get_products(); } } }); |
Heeft iemand een idee waarom hij niks doet met deze volgorde?
[ Voor 12% gewijzigd door TheNephilim op 25-01-2013 12:09 ]