dongxiqian2787 2009-07-01 11:34
浏览 23
已采纳

在jquery中选择通过AJAX检索的div

I'm creating a basic forum where every message contains the authors name, some text and the date it was created. I'd like the forum to update constantly through AJAX, and show new posts that were created on the fly. I currently have a PHP file getlatest.php?lastid=... that retrieves all posts from the ID given to the most current. It returns the data in HTML, like so (i've altered it so you can see the divs, stackoverflow throws them out):


foreach ($print as $value)
{
    $readyText .= div id = $value->post_id;
    $readyText .= $value->first_name.' '.$value->last_name.' posted the following:'.
    $value->post_text.' The post was made about '.$time.' ago. 
    $readyText .= '/div>'; 
}

I have some AJAX code in jquery that retrieves every few moments


setInterval("update()", 3000);
            function update()
            {
                $.get("getlatest.php", 
                {
                    id: latestmessage
                }, 
                function(response){
                    $("#forum_entries").prepend(response);
                    latestmessage = $.cookie('last_post_id'); //This is
                                      //how I know what the latest post id is
                }, "html");

I wanted to highlight all the new posts that were submitted using the (now very popular) yellow fade technique, like so

$("#somediv").effect("highlight", {}, 1500);

My question is - to what div to I apply this effect? I should add that back in PHP, every forum post had a div id that was actually its PK in the database.

  • 写回答

3条回答 默认 最新

  • douyi4991 2009-07-01 12:03
    关注

    Change your function so that instead of using prepend, it uses prependTo. PrependTo will return the elements that were prepended and you can apply the highlight to those elements (using jQuery 1.3.2).

      $.get('getlatest.php',
            { id: latestmessage }, 
            function(response) {
                $(response).prependTo('#forum_entries').effect('highlight',{},1500);
                latestmessage = $.cookie('last_post_id');
            }, 'html' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应