简体   繁体   English

NowJS错误! 我无法使示例工作!

[英]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. 当我遇到一些错误时,我正在按照http://nowjs.com/doc上的教程进行操作。

 <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. 我高度怀疑它与我的标签有关,因为/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 pages that are served through the same http server instance that was passed into the initialize function above. 在您要使用NowJS的页面上,只需在HTML头中包含此脚本标签:NowJS仅在通过上述初始化函数传递的同一http服务器实例提供服务的页面上起作用。

Thanks for your time. 谢谢你的时间。

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

脚本标签不能自动关闭。

在文档中,script标记中的路径是小写字母/nowjs/now.js ,而在您的代码段中则是/NowJS/now.js ,所以我想这就是它不起作用的原因。

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

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