Subversion Repositories SmartDukaan

Rev

Rev 36697 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36697 Rev 36819
Line 66... Line 66...
66
    } else {
66
    } else {
67
        internalServerErrorAlert(jqxhr);
67
        internalServerErrorAlert(jqxhr);
68
    }
68
    }
69
});
69
});
70
 
70
 
71
$(document).ajaxSend(function (ev, req) {
71
$(document).ajaxSend(function (ev, req, settings) {
-
 
72
    // Attach the idempotency key only to state-changing requests. GET/HEAD are
-
 
73
    // safe/repeatable and must not be pulled into server-side dedup.
-
 
74
    var method = (settings && settings.type ? settings.type : 'GET').toUpperCase();
-
 
75
    if (method === 'POST' || method === 'PUT' || method === 'PATCH' || method === 'DELETE') {
72
    req.setRequestHeader('IdempotencyKey', IdempotencyKey);
76
        req.setRequestHeader('IdempotencyKey', IdempotencyKey);
-
 
77
    }
73
});
78
});
74
 
79
 
75
$(document).ajaxSuccess(function () {
80
$(document).ajaxSuccess(function () {
76
    IdempotencyKey = uuidv4();
81
    IdempotencyKey = uuidv4();
77
    console.log('succcess handlor');
82
    console.log('succcess handlor');
Line 80... Line 85...
80
$(document).ajaxComplete(function () {
85
$(document).ajaxComplete(function () {
81
    if (typeof loaderDialogObj != "undefined") {
86
    if (typeof loaderDialogObj != "undefined") {
82
        loaderDialogObj.modal('hide');
87
        loaderDialogObj.modal('hide');
83
        // $('div.modal-backdrop.fade').remove();
88
        // $('div.modal-backdrop.fade').remove();
84
    }
89
    }
85
    IdempotencyKey = uuidv4();
90
    // NOTE: do NOT rotate IdempotencyKey here. ajaxComplete fires on every finish
-
 
91
    // (including errors/timeouts); rotating here gave each retry a fresh key and
-
 
92
    // defeated dedup. The key is reset only on confirmed success (ajaxSuccess),
86
    console.log("idempotency key", IdempotencyKey = uuidv4());
93
    // so a logical action and all its retries share a single key.
87
});
94
});
88
 
95
 
89
function ajaxStartHandler() {
96
function ajaxStartHandler() {
90
    if (typeof loaderDialogObj != "undefined")
97
    if (typeof loaderDialogObj != "undefined")
91
        loaderDialogObj.modal('show');
98
        loaderDialogObj.modal('show');