1

解决了

我只是在我的客户页面中更改innerText为。innerHTML


我有一个代码要测试,它在我的 google chrome 上运行良好,但在我的 Firefox 上不起作用!什么会导致问题?!

服务器代码:

var http = require('http'),
    io;

var html = require('fs').readFileSync("./index.html").toString('utf-8');

var server = http.createServer(function (request, response) {
    'use strict';
    response.statusCode = 200;
    response.setHeader('Content-Type', 'text/html');
    response.end(html);
});

server.listen(8124);

io = require('socket.io').listen(server);

function push(socket) {
    'use strict';

    var i = 0;
    return function () {
        socket.send(String(i++ % 3600));
    };
}

io.sockets.on('connection', function (socket) {
    'use strict';

    var interval = setInterval(push(socket), 1000);
    socket.on('disconnect', function () {
        clearInterval(interval);
    });
});

客户端代码:

<!DOCTYPE html>
<title>Socket.IO Example</title>
<div id="number"></div>
<script src="/socket.io/socket.io.js"></script>
<script>
    var io = io || undefined,
        socket = io.connect(),
        numberElement = document.getElementById('number');

    socket.on('message', function (data) {
        numberElement.innerText = data;
    });
</script>

火狐调试器

Error: The connection to ws://127.0.0.1:8124/socket.io/1/websocket/O_dTsMb1uMKPtpPdqSVG was interrupted while the page was loading.
Source File: http://127.0.0.1:8124/socket.io/socket.io.js
Line: 2371

该代码的第 2371 行是:

this.websocket = new Socket(this.prepareUrl() + query);

我该如何解决这个问题?!

4

0 回答 0