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

1 line
1.8 KiB
JSON

{"name":"ajaxStart","type":"method","title":".ajaxStart()","deprecated":null,"removed":null,"desc":"Register a handler to be called when the first Ajax request begins. 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":"Show a loading message whenever an Ajax request starts (and none is already active).","code":"\n$( document ).ajaxStart(function() {\n $( \"#loading\" ).show();\n});\n"},"longdesc":"\n <p>Whenever an Ajax request is about to be sent, jQuery checks whether there are any other outstanding Ajax requests. If none are in progress, jQuery triggers the <code>ajaxStart</code> event. Any and all handlers that have been registered with the <code>.ajaxStart()</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 ).ajaxStart(function() {\n $( \".log\" ).text( \"Triggered ajaxStart 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 is sent, the log message is displayed.</p>\n <p><strong>As of jQuery 1.8, the <code>.ajaxStart()</code> method should only be attached to <code>document</code>.</strong></p>\n "}]}