Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
Using patience is a virtue inside Ajax

I'm trying to use a patience is a virtue script in combination with Ajax.

For some reason the renable() doesn't get executed. The 'wheel' keeps spinning when I hit save. The record gets saved so the Ajax call should be complete after that.

This is what I have right now:

ajax-save.js

    import $ from 'jquery';
    import { patience_virtue, renable } from './patience-is-a-virtue';
    
    let form = $('#editcontent');
    let record_id = form.data('record');
    let element = $('button[name="save"]');
    
    record_id = JSON.stringify(record_id);
    /**
     * Start of Ajaxy solution for saving
     */
    element.click(function() {
        $.ajax({
            type: 'POST',
            link: '/edit/' + record_id,
            data: $(form).serialize(),
            beforeSend: patience_virtue(element),
            complete: renable(),
        });
    });

patience-is-a-virtue.js

    import $ from 'jquery';
    
    export function patience_virtue(thisElement) {
        const thisIcon = thisElement.find('i');
    
        // Bootstrap padding / margin like `mx-2` or `pt-3`
        const addedPadding = thisIcon.attr('class').match(/[mp][tblrxy]-[0-5]/i);
        const newClass = 'fas fa-w fa-cog fa-spin ' + (addedPadding ? addedPadding : '');
    
        thisElement.attr('data-original-class', thisIcon.attr('class'));
        thisIcon.attr('class', newClass);
    
        window.setTimeout(function() {
            thisElement.attr('disabled', true);
        }, 50);
    }
    
    export function renable() {
        $('*[data-original-class]').each(function() {
            const thisIcon = $(this).find('i');
    
            $(this).attr('disabled', false);
            thisIcon.attr('class', $(this).attr('data-original-class'));
        });
    }

Edit: It seems like $(this).attr('disabled') inside renable() is undefined. But console.log($(this)) returns the following: Showcase of console log

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!