Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to show different preloader gif based on different ajax calls?
    primarykey
    data
    text
    <p>I am currently using a preloader gif for my ajax calls with this code:</p> <pre><code>$(document).ajaxStart(function () { var position = $('#parentDiv').position(); position.left += (($('#parentDiv').width() / 2) - ($('#bigPreloader').width() / 2)); position.top += (($('#parentDiv').height() / 2) - ($('#bigPreloader').height() / 2)); $('#bigPreloader').css(position).show(); $('#bigPreloader').show(); }).ajaxStop(function () { $('#bigPreloader').hide(); }); </code></pre> <p>In the above code, #parentDiv takes up the majority of the page, and the preloader is 250x250 pixels and is centered in #parentDiv.</p> <p>This works fine, but I have just added some additional ajax calls that are associated with specific inputs, instead of the whole page. I have a small preloader (14x14 pixels) that I plan to put inside the appropriate input itself. </p> <p>Is there a way inside ajaxStart to determine which ajax call was made? Or is there a way to have multiple ajaxStarts linked to specific elements?</p> <p><strong>SOLUTION</strong></p> <pre><code>$(document).ajaxSend(function (event, jqxhr, settings) { if (settings.url.indexOf('LoadInputData') == -1) { var position = $('#parentDiv').position(); position.left += (($('#parentDiv').width() / 2) - ($('#bigPreloader').width() / 2)); position.top += (($('#parentDiv').height() / 2) - ($('#bigPreloader').height() / 2)); $('#bigPreloader').css(position).show(); $('#bigPreloader').show(); } else { $('#inputLoad').removeClass('notActive').addClass('isActive'); } }).ajaxStop(function () { if ($('#bigPreloader').is(':visible')) { $('#bigPreloader').hide(); } else { $('#inputLoad').removeClass('isActive').addClass('notActive'); } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload