control-freak-ide/Control-Freak-Documentation/jQuery/docs/entries/ajaxStop.json
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

1 line
1.9 KiB
JSON

{"name":"ajaxStop","type":"method","title":".ajaxStop()","deprecated":null,"removed":null,"desc":"Register a handler to be called when all Ajax requests have completed. This is an <ahref=\"/Ajax_Events/\">Ajax Event</a>.","categories":["ajax/global-ajax-event-handlers","version/1.0"],"entries":[{"return":"jQuery","signatures":{"added":"1.0","argument":{"desc":"The function to be invoked.","name":"handler()","type":"Function"}},"examples":{"desc":"Hide a loading message after all the Ajax requests have stopped.","code":"\n$( document ).ajaxStop(function() {\n $( \"#loading\" ).hide();\n});\n"},"longdesc":"\n <p>Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests. If none remain, jQuery triggers the <code>ajaxStop</code> event. Any and all handlers that have been registered with the <code>.ajaxStop()</code> method are executed at this time. The <code>ajaxStop</code> event is also triggered if the last outstanding Ajax request is cancelled by returning false within the <code>beforeSend</code> callback function. </p>\n <p>To observe this method in action, set up a basic Ajax load request:</p>\n <pre><code>\n&lt;div class=\"trigger\"&gt;Trigger&lt;/div&gt;\n&lt;div class=\"result\"&gt;&lt;/div&gt;\n&lt;div class=\"log\"&gt;&lt;/div&gt;\n </code></pre>\n <p>Attach the event handler to the document:</p>\n <pre><code>\n$( document ).ajaxStop(function() {\n $( \".log\" ).text( \"Triggered ajaxStop handler.\" );\n});\n </code></pre>\n <p>Now, make an Ajax request using any jQuery method:</p>\n <pre><code>\n$( \".trigger\" ).click(function() {\n $( \".result\" ).load( \"ajax/test.html\" );\n});\n </code></pre>\n <p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes, the log message is displayed.</p>\n <p><strong>As of jQuery 1.8, the <code>.ajaxStop()</code> method should only be attached to <code>document</code>.</strong></p>\n "}]}