展示“现场”的最佳方式评论

发布于 2024-10-05 23:04:11 字数 427 浏览 0 评论 0原文

我想在网格中显示用户评论(足够简单),但我也想显示新记录。理论上,用户会在此页面上停留一段时间,添加自己的评论并在其他人进来时查看其他人的评论。

它的行为非常像一个有多个用户发表评论的聊天窗口,尽管我不希望它如此活跃作为一个(我希望它会像 Facebook 墙一样间歇性更新)

我考虑过: - jQuery+AJAX+定时器?
- 网络套接字。 Web Socket 准备好迎来黄金时段了吗? Web Sockets可以用ASP.NET + IIS来实现吗?

我正在寻找一种优雅、干净、快速(低带宽;如果可能的话只加载新评论,弹出旧评论)的解决方案,并且在 ASP.NET/IIS 平台上不那么深奥...不知道如何为了解决这个问题,恳请您的帮助。

谢谢!

聚苯乙烯 我尝试在“评论系统”“显示新记录”“聊天系统”上搜索,但无法完全找到我想要的结果。

I want to show user comments in a grid (easy enough) but I want to show the new records as they come in as well. In theory, the user stays on this page a while, adding their own comments and viewing others' as they come in.

It behaves very much like a chat window with multiple users making comments, though I don't expect it to be as active as one (I expect it to be about as intermittently-updated as a Facebook wall)

I've considered:
- jQuery+AJAX+Timer?
- Web Sockets. Are Web Sockets ready for prime time? And can Web Sockets be implemented with ASP.NET + IIS?

I'm looking for a solution that is elegant, clean, fast (low bandwidth; only load the new comments if possible, popping off the older ones) and not so esoteric on an ASP.NET/IIS platform...not sure how to go about this, kindly requesting your help.

Thanks!

PS
I tried searching on "comment system" "show new records" "chat systems", but couldn't quite hit the results I sought.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿忘初心 2024-10-12 23:04:11

其他人可能有更好的例子,但我正在使用 AJAX 聊天 Web 应用程序。这是我使用 ASP.net 和 JQuery 所做的事情。

<script type="text/javascript">
    $(document).ready(function () {
        $("#btnSend").click(function () {
            addMessage();
        });
        return false;
    });

    function refreshChat() {
        $.get("messages.aspx", function (data) {
            $("#chatbox").empty();
            $("#chatbox").prepend(data);
            var $t = $("#chatbox"); //whatever the selector you use.
            $t.animate({ scrollTop: $t.attr("scrollHeight") }, 3000);
        });

        setTimeout(refreshChat, 5000);
    }

    function addMessage() {
        $.get("messages.aspx", { usr: $("#usr").val(), msg: $("#msg").val() });
        $("#msg").val('');
        $("#msg").focus();
    }
</script>

HTML:

<div id="input">
    username:
    <input type="text" name="usr" id="usr" /><br />
    message:
    <textarea rows="3" id="msg" name="msg"></textarea>
    <br />
    <input type="button" id="btnSend" name="btnSend" value="Send" />
</div>
<div id="chatbox" style="height: 300px; overflow: scroll;">
</div>

使用 message.aspx 将新消息记录到数据库中,并查询新记录以添加到 msg div 中。

Someone else may have a better example, but I was playing around with a AJAX chat web app. Here's what I did using ASP.net and JQuery.

<script type="text/javascript">
    $(document).ready(function () {
        $("#btnSend").click(function () {
            addMessage();
        });
        return false;
    });

    function refreshChat() {
        $.get("messages.aspx", function (data) {
            $("#chatbox").empty();
            $("#chatbox").prepend(data);
            var $t = $("#chatbox"); //whatever the selector you use.
            $t.animate({ scrollTop: $t.attr("scrollHeight") }, 3000);
        });

        setTimeout(refreshChat, 5000);
    }

    function addMessage() {
        $.get("messages.aspx", { usr: $("#usr").val(), msg: $("#msg").val() });
        $("#msg").val('');
        $("#msg").focus();
    }
</script>

HTML:

<div id="input">
    username:
    <input type="text" name="usr" id="usr" /><br />
    message:
    <textarea rows="3" id="msg" name="msg"></textarea>
    <br />
    <input type="button" id="btnSend" name="btnSend" value="Send" />
</div>
<div id="chatbox" style="height: 300px; overflow: scroll;">
</div>

Use the message.aspx to record new messages into a database and query for new records to add to the msg div.

木落 2024-10-12 23:04:11

试试这个

var Interval=2; // 页面加载时

ajax 每 2 秒与服务器同步一次,并且在 鼠标上 ||键盘事件重置间隔为 2,每 10 个 ajax 调用将刷新间隔增加 1 秒。这样您就可以控制服务器负载。并将节省客户端和服务器的带宽。

这些值可以根据您的需要进行调整

Try this

var interval=2; // on page load

ajax syncing with server for every 2 seconds and on mouse || keyboard event reset interval to 2 and every 10 ajax calls increase the refresh interval by 1 sec. This way you can control server load. and will save bandwidth for client and server.

These values can be adjusted as per your needs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文