开发者

NowJS error! I can't get the example to work!

I was following along the tutorial at http://nowjs.com/doc when I encountered some errors.

 <html>
<head>
    <title>index.html</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"/>
    <script src="http://localhost:8080/NowJS/now.js"></script>
    <script>
    $(document).ready(function(){
        var name = prompt("what is your name?","");
        now.receiveMessage = function(name,message){
            alert(name+" "+message);    

        };

        $('.butt').click(function(){
            alert($('#put').val());
            now.distributeMessage(name,$('#put').val());


        $('#put').val('');
    });
});

</script>

and for the server:

 var fs = require('fs');
var sys = require('sys');
var server = require('http').createServer(function(req,response){
    fs.readFile('index.html',function(err,data){
        response.writeHead(200);    
        response.write(data);
        response.end();
    });

});
server.listen(8080);
sys.print('woot');

var everyone = require('now').initialize(server);

everyone.now.distributeMessage = function(name, message){
    sys.print(name+"   "+message);
    everyone.now.receiveMessage(name,message);

};

I highly suspect it has something to do with my tag since there isnt anything at /NowJS/now.js. Can someone enlighten me on this part:

On pages that you would like to use NowJS on, simply include this script tag in your HTML head: NowJS only works on 开发者_C百科pages that are served through the same http server instance that was passed into the initialize function above.

Thanks for your time.


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"/>

script tags can't be self-closed.


In the docs the path in the script tag is lower-case, /nowjs/now.js, whereas in your snippet it is /NowJS/now.js, and so I guess this is the reason it doesn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜