为什么我的节点事件回调显示为未定义的事件
Why is my node event callback showing up in the event as undefined?
我正试图将url字符串作为"数据"传递回我的eventandler。
我对服务器的请求是"https://172.20.10.6/index.html"。下面的console.log
如我所料打印出"/index.html"。
switch(req.method) {
case 'GET':
console.log("logged from plugin-https.js: url: " + req.url);
ee.emit("dataIn", req.url);
break;
下面是eventandler代码。console.log(data);
的计算结果为"undefined"。我想知道为什么会这样。这似乎是一个非常简单的直接回调,所以我想知道为什么数据在eventhandhandling代码中出现时没有定义。
plugin = rtrn;
console.log('4');
plugin.dataIn(config, function(err, data) {
if(err, data) {
console.log('error geting data');
} else {
// This is where request events are being handled.
console.log(data);
console.log('We are in the event handling codeblock of funtion startRuntime() located in interactor.js');
还有,这是我的回调代码
var ee = new events.EventEmitter();
function dataIn(config, callback) {
if(typeof callback === 'function') {
ee.on("dataIn", callback);
看起来你在吞错误。
if(err, data) {
console.log('error geting data');
}
条件(err, data)
将忽略err
的值。如果data
是未定义的,它将是假的,你不会知道你有一个错误。您可能想要更像这样的内容:
if (err) {
console.log('error getting data')
}
追溯到你的发射器,你发射的方式发送你的数据到第一个参数,这应该是错误的地方。所以这:
ee.emit("dataIn", req.url);
…应该更像这样:
ee.emit("dataIn", null, req.url);
相关文章:
- $window.ga在AngularJS事件中未定义
- 事件在加载之前时的未定义位置
- Razor Dropdown onchange事件未触发始终未定义
- ui.columnIndex在igGridHiding-columnShowing事件中未定义
- ReferenceError:事件未在Firefox中定义错误
- 包含的javascript源代码通过PHP,onmousemove事件,函数未定义
- InAppBrowser事件.url始终未定义
- 自定义jQuery插件:事件未按预期运行
- 事件未定义 火狐.
- 事件未定义错误在 javascript 中只有 Firefox
- 事件未定义错误,仅在火狐中
- 事件未定义 JavaScript Firefox (JSON)
- JS Revearing Pattern事件未定义问题
- 事件未定义 FF
- ReferenceError:事件未定义firefox d3.js
- 为什么使用a.c click时事件未定义?
- "事件未定义“;在firefox中
- 类型错误:firefox中关于javascript的事件未定义
- jQuery onkeyup事件:未定义扫描
- IE8中的图像加载事件;事件未定义,这是“窗口”对象