socket.io 在IE下面无法连接
发布于 1年前 作者 lmh2072005 1264 次浏览

我用的IE9 试了下IE8 IE7 也是一样无法连接无法emit 不知道什么原因 在firefox chrome 下都是正常的 求助 !!! chat.js 内容:

var express = require(‘express’), app = express(), http = require(‘http’), server = http.createServer(app).listen(8000, function(){console.log(‘server listen on 8000’)}); var io = require(‘socket.io’).listen(server);

app.get(‘/’,function(req, res){ res.sendfile(__dirname+’/chat.html’); })

io.set('transports’, ['websocket’,’flashsocket’, 'htmlfile’, 'xhr-polling’, ‘jsonp-polling’]);

io.sockets.on('connection’, function(socket) { socket.on('msg’, function(data) { socket.broadcast.emit('showmsg’,data); }); socket.on('disconnect’, function() { // handle disconnect }); });

静态文件 chat.html :

<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>chat test</title>
</head>
<body>
    <form id="form">
    message: <input type="text" id='msg' value=""/>
    <input type="submit" value="send" id="send"/> 
    </form>
    <div id="showResult"></div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script src="/socket.io/socket.io.js"></script>
    <script>
        var socket = io.connect(),
        result = $('#showResult');
        socket.on('connect', function() {
              result.append($('<p>').text('Connected')); 
        });
         
        socket.on('showmsg', function(msg) {
          result.append($('<p>').text(msg).append($('<em>').text(' from server')));
        });
         
        $('#form').submit(function(e) {
          e.preventDefault();
          var msg = $('#msg').val();
          result.append($('<p>').text(msg).append($('<em>').text(' from me')));
          socket.emit('msg',msg);
        }); 
    
    </script>
</body>

</html>

2 回复

没人回复啊 难道没人遇到这种问题吗 ,求助大神 !

**忘记说了,在本地用localhost访问IE是可以的 ,换成局域网的192.168.1.133或外网的地址IE就不行了

回到顶部