ajaxComplete()方法用于指定AJAX请求完成时要运行的功能。
用法:
$(document).ajaxComplete(function(event, xhr, options))
参数:
event:它包含事件对象。
xhr:它包含XMLHttpRequest对象。
options:它包含AJAX请求中使用的选项。
The demo.txt file stored on the server and it will load after clicking the change content button.
The content of demo.txt are:
This is GFG.
示例1:本示例通过从服务器获取数据来更改元素的内容。 AJAX请求完成后,页面上会显示AJAX请求完成。
$(document).ready(function() {
$(document).ajaxComplete(function() {
alert(" AJAX request completes.");
});
$("button").click(function() {
$("#paragraph").load("demo.txt");
});
});
body {
text-align: center;
}
GeeksforGeeks
style="font-size: 20px;">
A computer science portal for geeks
Change Content
输出:
在点击按钮之前
点击按钮后
示例2:本示例通过从服务器获取数据来更改元素的内容。 AJAX请求完成后,页面上会显示AJAX请求完成。
$(document).ready(function() {
$(document).ajaxComplete(function() {
alert("AJAX request completes.");
});
$("button").click(function() {
$("#paragraph").load("demo.txt");
});
});
body {
text-align: center;
}
GeeksforGeeks
style="font-size: 20px;">
A computer science portal for geeks
Change Content
输出:
在点击按钮之前
点击按钮后