简体   繁体   English

刷新div而不用jquery重新加载页面

[英]Refresh div without reload the page with jquery

I have a page in php and I need to refresh only a div of this page 我在php中有一个页面,我只需刷新此页面的div

<body>
 .... page code here ....
?><div id="chattext">
            <div id="list"><ul><?php
                echo "ttt ".time();
                ... code php ...
</body>

In head tag I hage this code 在head标签中我讨厌这段代码

<script>

$(document).ready(function()
{
    $.ajaxSetup(
    {
        cache: false,
        beforeSend: function() {
            $('#chattext').hide();
            //$('#loading').show();
        },
        complete: function() {
            //$('#loading').hide();
            $('#chattext').show();
        },
        success: function() {
            //$('#loading').hide();
            $('#chattext').show();
        }
    });        
    var url='index.php';
    var refreshId = setInterval(function()
    {            
        $('#chattext').load(url + '#list');
    }, 3000);
});

The problem is that che the first time reload all page inside the block and only from the second time reload correctly only the div.... Why??? 问题是,第一次重新加载块内的所有页面,只有从第二次正确重新加载只有div ....为什么??? how can I resolve the problem??? 我怎么解决这个问题?

In the code where you load the page fragment 在您加载页面片段的代码中

$('#chattext').load(url + '#list');

It needs to have a space between the url and the fragment identifier 它需要在url和片段标识符之间有一个空格

$('#chattext').load(url + ' #list');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM