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

1 line
2.8 KiB
JSON

{"name":"ajaxSuccess","type":"method","title":".ajaxSuccess()","deprecated":null,"removed":null,"desc":"Attach a function to be executed whenever an Ajax request completes successfully. 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(event, XMLHttpRequest, ajaxOptions)","type":"Function"}},"examples":{"desc":"Show a message when an Ajax request completes successfully.","code":"\n$( document ).ajaxSuccess(function( event, request, settings ) {\n $( \"#msg\" ).append( \"<li>Successful Request!</li>\" );\n});\n"},"longdesc":"\n <p>Whenever an Ajax request completes successfully, jQuery triggers the <code>ajaxSuccess</code> event. Any and all handlers that have been registered with the <code>.ajaxSuccess()</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 any element:</p>\n <pre><code>\n$(document).ajaxSuccess(function() {\n $( \".log\" ).text( \"Triggered ajaxSuccess handler.\" );\n});\n </code></pre>\n <p>Now, make an Ajax request using any jQuery method:</p>\n <pre><code>\n$( \".trigger\" ).on( \"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 successfully, the log message is displayed.</p>\n <p><strong>As of jQuery 1.8, the <code>.ajaxSuccess()</code> method should only be attached to <code>document</code>.</strong></p>\n <p>All <code>ajaxSuccess</code> handlers are invoked, regardless of what Ajax request was completed. If you must differentiate between the requests, you can use the parameters passed to the handler. Each time an <code>ajaxSuccess</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 ).ajaxSuccess(function( event, xhr, settings ) {\n if ( settings.url == \"ajax/test.html\" ) {\n $( \".log\" ).text( \"Triggered ajaxSuccess handler. The ajax response was: \" +\n xhr.responseText );\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.responseText</code> for xml and html respectively.</p>\n "}]}