JSFiddle - React, Tailwind, and code Playground

by richardneililagan

JavaScript

jQuery(function($) {
    
    $('foo').click(function () {
        
        // click event starts AJAX
        
        var _t = $(this);
        
        // set flag
        _t.data('ajaxflag', true);
        
        // start AJAX call
        $.ajax({            
            url : 'your.domain.com/path/to/rest/endpoint',
            data : '{}',
            type : 'POST',
            contentType : 'application/json'   
            
        }).complete(function (m) {
            // check flag if we should continue            
            var _flag = _t.data('ajaxflag');            
            // forced FALSY | failsafe
            if (!_flag) { return; }
            
            // if we continue, then so do something
            // blah blah            
        });             
        
    }).dblclick(function () {
        
        // double click event cancels the flag, 
        // so that when the AJAX completes,
        // the complete function callback will return prematurely
        
        $(this).removeData('ajaxflag');
        
    });
        
    
});