刷新一个DIV不重新加载整个页面 [英] Reload a DIV without reloading the whole page

查看:1378
本文介绍了刷新一个DIV不重新加载整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div标签,有一个PHP的包括,以填补该div的信息 我想要做的就是让这个页面被称为每15秒,因此它可以有更新信息,而无需重新加载整个网页。 我试着用JavaScript / jQuery的这么做,我只是似乎无法得到它的工作

I have a Div Tag that has a php include to fill that div with information what I want to do is make it so that the page is called every 15s so it can update the information there without having to reload the whole webpage. I've tried to do this with JavaScript/jQuery and I just can't seem to get it to work

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
$('.View').load('Small.php').fadeIn("slow");
}, 15000); // refresh every 15000 milliseconds
</script>

<div class="View"><?php include 'Small.php'; ?></div>

这是我寻找了一些后,会发生什么,它加载Small.php,但它不刷新或更新信息,每隔1​​5秒。

this is what I have after searching some, and what happens is, it loads the Small.php but it doesn't refresh it or update the info every 15 seconds.

请大家帮帮忙!

我要补充我所有的PHP数组,应该出现在该Small.php所有执行和网页,我包括它变成只是所以它的孤立。

I should add all my php arrays that should show up are all executed in the Small.php and the page I'm including it into is just so it's isolated.

编辑:什么没有人注意到的是,我的第一个脚本引用的jQuery没有结束标签,那就是打破我的第二个脚本。在一个适当的结束标记添加后,剧本终于工作,但淡入并不没有首先使用淡出正确显示。

What No One noticed was that my first script referencing jQuery did not have a closing tag, and that was breaking my second script. after adding in a proper closing tag, the script was finally working, but the fadeIn does not show properly without first using a fadeOut.

推荐答案

您code ++工程,但淡入不会,因为它已经显现。我想你想达到的效果是:淡出&RARR; 负荷&RARR; 淡入

Your code works, but the fadeIn doesn't, because it's already visible. I think the effect you want to achieve is: fadeOutloadfadeIn:

var auto_refresh = setInterval(function () {
    $('.View').fadeOut('slow', function() {
        $(this).load('/echo/json/', function() {
            $(this).fadeIn('slow');
        });
    });
}, 15000); // refresh every 15000 milliseconds

在这里试一试: http://jsfiddle.net/kelunik/3qfNn/1/

其他注意事项:由于庆所提到,您可能需要摆​​脱浏览器的内部缓存中。你可以这样做,使用 $ AJAX $ ajaxSetup({缓存:假}); 或随机黑客,他提到了。

Additional notice: As Khanh TO mentioned, you may need to get rid of the browser's internal cache. You can do so using $.ajax and $.ajaxSetup ({ cache: false }); or the random-hack, he mentioned.

这篇关于刷新一个DIV不重新加载整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆