Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The .ajaxStart() will only fire if all other calls have finished. If no requests are in progress it then fires the code in ajaxStart. So if you are using asynchronous requests this method wouldn't be of much help except if all the previous requests have finished running.</p> <p>To solve your question I would suggest using the <a href="http://api.jquery.com/ajaxSend/" rel="nofollow">.ajaxSend()</a> method instead. This method fires every time, just before a request is about to be sent out. So it does almost the same thing as .ajaxStart(). To differentiate between requests you can use the parameters passed to the handler function. There are several things you could test for, but probably easiest to just go for the URL, like so:</p> <p>Ex from jQuery docs:</p> <pre><code>$(document).ajaxSend(function(event, jqxhr, settings) { if ( settings.url == "ajax/test.html" ) { //Test by URL //Do your specific pre-loader stuff here } }); </code></pre> <p>You can also set the context in your specific request. Doing this will set the <code>$(this)</code> selector to the context you specified, thus allowing you to separate the logic from the DOM as well. This way you can have a single function with the loader set up, that gets posted on the element you set in the context.</p> <pre><code>$.ajax({ url: "test.html", context: document.body }).done(function() { $(this).addClass("done"); //$(this) is the document.body or could be the element you want to put your specific loader in. }); </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.
 

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