OpWeb[0.0.3]--光速无服务端创建一个AJXA聊天程序

20 篇文章 0 订阅
10 篇文章 0 订阅

   上一篇我们简单测试了如何快速构建一个聊天程序,虽然很简单很Demo.但是依然摆脱不了B/S的方式去开发.

   现在OpWeb[0.0.3]版本给你带来了更令人兴奋的开发方式,全客户端模式.更快速,更便捷的开发模式.

   废话不说,直接上index.html

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="../Shared/watch.js" type="text/javascript"></script>
    <script src="watch.js" type="text/javascript"></script>
    <script src="../Shared/util.js" type="text/javascript"></script>
    <script src="util.js" type="text/javascript"></script>
    <script src="http://localhost:8000/_comet.io/comet.io.client.js"></script>
    <title>easy chat test</title>
</head>
<body>

    <div id="content">
    </div>

    <p>
        <input type="text" name="word" id="word" value="" />
    </p>

    <script>
        //define root class
        var chatList =  function(){
            var self = this;
            //message list
            this.lists = [];
            //watch on change
            doUIWatch(this,function(prop, action, newval, oldval){
                if(action == "push" )
                {
                    //if lists add a item,add a div message in ui
                    $('#content').append('<div>' + newval[0].message + '</div>');
                }
            })
        };

        //new a root item
        var chatRoot = new chatList();
        //bind item to a sync session
        var session1=new opSession(chatRoot,"10000","http://localhost:8000",true);
        //if user input on and enter add a new message
        $('#word').bind('keydown', function (e) {
            var key = e.which;
            if (key == 13) {
                chatRoot.lists.push({ message : $('#word').val()});
            }
        });

    </script>

</body>
</html>
完了??完了!!!

这是单机版本吧?不信?

你打开2个试试....

DEMO已包含到框架中:

OpWeb框架 : https://github.com/icesun963/OpWeb/

框架介绍:http://blog.csdn.net/icesun963/article/details/17194193

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值