簡體   English   中英

套接字io get未定義

[英]Socket io get is undefined

我正在使用Sails JS,並且嘗試使用套接字IO librarie。

正如Sails JS文檔中所述: http ://sailsjs.org/#!documentation/ sockets

我用以下代碼創建一個控制器:

index: function(req, res) {

    var param = req.param('msg');

    console.log("PARAM : ", param); // For display the message in terminal

    // Send a JSON response
    return res.json({
        success: true,
        message: param
    });
},

在我的模板中(我使用swig JS模板引擎):

對於include socket io庫:

<script type="text/javascript" src="/socket.io/socket.io.js"></script>

在JavaScript代碼中:

var socket = io.connect('http://localhost:1337');

socket.get('/echo', {
    message: 'hi there!'
}, function(response) {
    console.log ('response : ', response);
});

而且我有這個錯誤:undefined不是socket.get('/ echo'...

謝謝你的幫助 !

我相信您也需要添加<script type="text/javascript" src="/app/sails.io.js"></script> 由於Socket.prototype.get是在此文件中定義的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM