如何调用jQuery ajaxStart + ajaxComplete [英] How to call jquery ajaxStart + ajaxComplete
问题描述
我有一个加载功能,并想为code写一些HTML到一个div而它加载,并完成时,显示该页面。我看到ajaxStart和ajaxComplete事件的一些小writeups,但我不知道如何实现它们。
下面是jQuery的,我想用的,但是不知道怎么中的code我目前正在实施......
$(文件).ajaxStart(函数(){
$('#内容)HTML(正在加载内容......)。
});
下面是我使用的是当前的jQuery:
//加载内容
$(装载)。点击(函数(){
$(#内容),空()。
loadName = $(本).attr(ID);
$(#内容)加载(/内容/+ loadName +.PHP)。
});
如果它是一个单独的分区,你想更新其内容的加载消息/指示器,你可以这样做是这样的:
$(#内容)HTML('<强>载入中...< / STRONG>')
.load(/内容/+ loadName +.PHP);
我不会使用 ajaxStart
和 ajaxStop
/ ajaxComplete
全球活动的,除非你有一个共同的装载指标的所有的Ajax调用。这就是说,它可以做如下:
$(#加载)。绑定(ajaxStart,函数(){
$(本).show();
})绑定(ajaxStop,函数(){
$(本).hide();
});
其中加载
元素是任何你想要的Ajax调用时透露。
I have a load function and would like for the code to write some html into a div while it loads, and when it completes, to display the page. I saw some little writeups on the ajaxStart and ajaxComplete events, however I am not sure how to implement them.
Here is the jquery I am thinking of using, however not sure how to implement within the code I have currently…
$(document).ajaxStart(function(){
$('#content').html("Loading Content...");
});
Here is the current jquery I am using:
//Load content
$(".load").click(function(){
$("#content").empty();
loadName = $(this).attr("id");
$("#content").load("/content/" + loadName + ".php");
});
If it's a single div and you would like to update its contents with a loading message/indicator, you can do so like this:
$("#content").html('<strong>Loading...</strong>')
.load("/content/" + loadName + ".php");
I wouldn't use the ajaxStart
and ajaxStop
/ajaxComplete
global events unless you have a common loading indicator for all ajax calls. That said, it can be done as follows:
$("#loading").bind("ajaxStart", function(){
$(this).show();
}).bind("ajaxStop", function(){
$(this).hide();
});
where the loading
element is whatever you want to reveal during an ajax call.
这篇关于如何调用jQuery ajaxStart + ajaxComplete的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!