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

1 line
2.7 KiB
JSON

{"name":"ajaxComplete","type":"method","title":".ajaxComplete()","deprecated":null,"removed":null,"desc":"Register a handler to be called when Ajax requests complete. This is an <ahref=\"/Ajax_Events/\">AjaxEvent</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(event, XMLHttpRequest, ajaxOptions)","type":"Function"}},"examples":{"desc":"Show a message when an Ajax request completes.","code":"\n$( document ).ajaxComplete(function( event,request, settings ) {\n $( \"#msg\" ).append( \"<li>Request Complete.</li>\" );\n});\n"},"longdesc":"\n <p>Whenever an Ajax request completes, jQuery triggers the <code>ajaxComplete</code> event. Any and all handlers that have been registered with the <code>.ajaxComplete()</code> method are executed at this time.</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 ).ajaxComplete(function() {\n $( \".log\" ).text( \"Triggered ajaxComplete 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>.ajaxComplete()</code> method should only be attached to <code>document</code>.</strong></p>\n <p>All <code>ajaxComplete</code> handlers are invoked, regardless of what Ajax request was completed. If you must differentiate between the requests, use the parameters passed to the handler. Each time an <code>ajaxComplete</code> handler is executed, it is passed the event object, the <code>XMLHttpRequest</code> object, and the settings object that was used in the creation of the request. For example, you can restrict the callback to only handling events dealing with a particular URL:</p>\n <pre><code>\n$( document ).ajaxComplete(function( event, xhr, settings ) {\n if ( settings.url === \"ajax/test.html\" ) {\n $( \".log\" ).text( \"Triggered ajaxComplete handler. The result is \" +\n xhr.responseHTML );\n }\n});\n </code></pre>\n <p><strong>Note:</strong> You can get the returned ajax contents by looking at <code>xhr.responseXML</code> or <code>xhr.responseHTML</code> for xml and html respectively.</p>\n "}]}