Press "Enter" to skip to content

A Lightweight jQuery Execute Function Before AJAX Call Ends | Just Wait

Just Wait is a lightweight jQuery utility that allows you to specify a job that will run after a specified period of time from the start of an AJAX request. If AJAX requests finish before the specified time period, the job will never be executed.

Key Features:

  • AJAX request begins.
  • Start counting to the specified amount of time (default is 100ms).
  • Determine if the AJAX request has expired or not.
  • If yes, stop counting.
  • If no, determine whether a specified period of time has passed since the AJAX request was initiated.
  • If yes, call back ().

How to make use of it:

1. Download & unzip the plugin after which insert the just-wait.min.js after jQuery.

<script src="/path/to/cdn/jquery.min.js"></script>
<script src="/path/to/dist/just-wait.min.js"></script>

2. Add the wait() callback to your AJAX request.

  .wait(() => {
    // do something after 100ms (default)
  .done((data) => { 
    // do something after the data is fetched
  .fail(() => { 
    // do something when the data fails to load
  .always(() => { 
    // do something after The AJAX request ends.

3. override the default JustWait time in milliseconds.

JustWait.options.waitFor = 300;

// or
  url: '/path/to/data',
  waitFor: 300

  url: '/path/to/data',
  waitFor: 300

  url: '/path/to/data',
  data: { id: 3 },
  waitFor: 300

Execute function after Ajax call, Just Wait Plugin/Github

See Demo And Download

Official Website(OmarMuscatello): Click Here

This superior jQuery/javascript plugin is developed by OmarMuscatello. For extra Advanced Usages, please go to the official website.

Be First to Comment

    Leave a Reply

    Your email address will not be published.