Tôi có một sự trở lại văn bản/luồng sự kiện
URL của dữ liệu, vì vậy tôi cố gắng kết nối và in mọi thứ tôi tìm thấy:
var url = "..."
var source = new EventSource(url);
source.addEventListener('message', function(e) {
console.log(e.data);
}, SAI);
source.addEventListener('open', function(e) { }, false);
source.addEventListener('error', function(e) {
if (e.readyState == EventSource.CLOSED) { }
}, SAI);
Thật không may, điều này không hoạt động ở phía máy chủ. Tôi có thể kết nối như thế này không?
$nodeapp.js
ứng dụng.js:2
var source = new EventSource(url);
^
ReferenceError: EventSource không được xác định
tại Object. (app.js:2:18)
tại Module._compile (module.js:409:26)
tại Object.Module._extensions..js (module.js:416:10)
tại Module.load (module.js:343:32)
tại Function.Module._load (module.js:300:12)
tại Function.Module.runMain (module.js:441:10)
lúc khởi động (node.js:139:18)
tại node.js:968:3
Có vẻ như bạn đã quên phía máy chủ:
var EventSource = require("eventsource");
Tôi là một lập trình viên xuất sắc, rất giỏi!