Jquery-ajaxstop
提供:Dev Guides
jQuery-ajaxStop(コールバック)メソッド
説明
- ajaxStop(callback)*メソッドは、すべてのAJAXリクエストが終了するたびに実行される関数をアタッチします。 これはAjaxのイベントです。
構文
このメソッドを使用するための簡単な構文は次のとおりです-
$(document).ajaxStop( callback )
パラメーター
これは、この方法で使用されるすべてのパラメータの説明です-
- callback -実行する関数。
例
結果ファイルに次のHTMLコンテンツがあると仮定します-
<h1>THIS IS RESULT...</h1>
以下は、このメソッドの使用方法を示す簡単な例です。
<html>
<head>
<title>The jQuery Example</title>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
/*Global variable*/
var count = 0;
$("#driver").click(function(event){
$('#stage0').load('resultl');
});
/*Gets called when request starts*/
$(document).ajaxStart(function(){
count++;
$("#stage1")l("<h1>Starts, Count :" + count + "</h1>");
});
/*Gets called when request is sent*/
$(document).ajaxSend(function(evt, req, set){
count++;
$("#stage2")l("<h1>Sends, Count :" + count + "</h1>");
$("#stage2").append("<h1>URL :" + set.url + "</h1>");
});
/*Gets called when request complete*/
$(document).ajaxComplete(function(event,request,settings){
count++;
$("#stage3")l("<h1>Completes, Count :" + count + "</h1>");
});
/*Gets called when all requests are ended*/
$(document).ajaxStop(function(event,request,settings){
count++;
$("#stage4")l("<h1>Stops, Count :" + count + "</h1>");
});
});
</script>
</head>
<body>
<p>Click on the button to load resultl file:</p>
<div id = "stage0" style = "background-color:blue;">
STAGE - 0
</div>
<div id = "stage1" style = "background-color:blue;">
STAGE - 1
</div>
<div id = "stage2" style="background-color:blue;">
STAGE - 2
</div>
<div id ="stage3" style = "background-color:blue;">
STAGE - 3
</div>
<div id = "stage4" style = "background-color:blue;">
STAGE - 4
</div>
<input type = "button" id = "driver" value = "Load Data"/>
</body>
</html>
これにより、次の結果が生成されます–