my jQuery below reloads the reloadhomeposts.php file. My question is how can I keep the reloaded data and not be disappeared until the fresh loaded content will be shown?
下面的jQuery重新加载了reloadhomeposts。php文件。我的问题是,在显示新加载的内容之前,如何保存已重新加载的数据而不消失?
<script language="JavaScript">
$(function () {
function loadReservationDetails() {
$('#reservationdetails')
.empty()
.addClass('loading')
.load('wp-content/themes/theme/reloadhomeposts.php', function () {
$(this).removeClass('loading');
setTimeout(loadReservationDetails, 20000);
});
}
loadReservationDetails();
});
</script>
4 个解决方案
#1
3
just don't call the .empty()
method like so:
不要像这样调用.empty()方法:
<script language="JavaScript">
$(function () {
function loadReservationDetails() {
$('#reservationdetails')
.addClass('loading')
.load('wp-content/themes/theme/reloadhomeposts.php', function () {
$(this).removeClass('loading');
setTimeout(loadReservationDetails, 20000);
});
}
loadReservationDetails();
});
</script>
#2
1
It's the call to empty
that is removing the current content before the request is sent. Just remve that call, and the current content remains until it's replaced by the new data in the response:
调用empty是在发送请求之前删除当前内容。只要记住这个调用,当前的内容就会保留,直到它被响应中的新数据所取代:
<script type="text/javascript">
$(function () {
function loadReservationDetails() {
$('#reservationdetails')
.addClass('loading')
.load('wp-content/themes/theme/reloadhomeposts.php', function () {
$(this).removeClass('loading');
window.setTimeout(loadReservationDetails, 20000);
});
}
loadReservationDetails();
});
</script>
#3
0
Load data to another div, and then swap it with your first div.
将数据加载到另一个div,然后与第一个div交换数据。
#4
0
No need to call .empty()
as old data will automatically be replaced with the new one. Like:
不需要调用.empty(),因为旧数据将自动替换为新数据。如:
$(function () {
function loadReservationDetails() {
$('#reservationdetails')
.addClass('loading')
.load('wp-content/themes/theme/reloadhomeposts.php', function () {
$(this).removeClass('loading');
setTimeout(loadReservationDetails, 20000);
});
}
loadReservationDetails();
});
#1
3
just don't call the .empty()
method like so:
不要像这样调用.empty()方法:
<script language="JavaScript">
$(function () {
function loadReservationDetails() {
$('#reservationdetails')
.addClass('loading')
.load('wp-content/themes/theme/reloadhomeposts.php', function () {
$(this).removeClass('loading');
setTimeout(loadReservationDetails, 20000);
});
}
loadReservationDetails();
});
</script>
#2
1
It's the call to empty
that is removing the current content before the request is sent. Just remve that call, and the current content remains until it's replaced by the new data in the response:
调用empty是在发送请求之前删除当前内容。只要记住这个调用,当前的内容就会保留,直到它被响应中的新数据所取代:
<script type="text/javascript">
$(function () {
function loadReservationDetails() {
$('#reservationdetails')
.addClass('loading')
.load('wp-content/themes/theme/reloadhomeposts.php', function () {
$(this).removeClass('loading');
window.setTimeout(loadReservationDetails, 20000);
});
}
loadReservationDetails();
});
</script>
#3
0
Load data to another div, and then swap it with your first div.
将数据加载到另一个div,然后与第一个div交换数据。
#4
0
No need to call .empty()
as old data will automatically be replaced with the new one. Like:
不需要调用.empty(),因为旧数据将自动替换为新数据。如:
$(function () {
function loadReservationDetails() {
$('#reservationdetails')
.addClass('loading')
.load('wp-content/themes/theme/reloadhomeposts.php', function () {
$(this).removeClass('loading');
setTimeout(loadReservationDetails, 20000);
});
}
loadReservationDetails();
});