Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //timed update
- function refresh() {
- if (BLOCKED != 1) {
- BLOCKED = 1;
- $.ajax({
- url: 'update',
- success: function(data) {
- BLOCKED = 0;
- }
- });
- }
- //click function
- function load() {
- if (BLOCKED != 1) {
- BLOCKED = 1;
- $.ajax({
- url: '/load'
- });
- } else setTimeout("load()", 500);
- }
- // global state
- var inFlight = false;
- var pendingLoad = false;
- function checkPendingLoad() {
- if (pendingLoad) {
- pendingLoad = false;
- load();
- }
- }
- function refresh() {
- if (!inFlight) {
- inflight = true;
- $.ajax({
- url: 'update',
- complete: function(data) {
- inFlight = false;
- checkPendingLoad();
- }
- });
- }
- }
- //click function
- function load() {
- if (!inFlight) {
- inFlight = true;
- $.ajax({
- url: '/load',
- complete: function(data) {
- inFlight = false;
- checkPendingLoad();
- }
- });
- } else {
- pendingLoad = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement