简体   繁体   English

回调延迟时,NodeJS无法响应。写入浏览器

[英]NodeJS unable to response.write to the browser when there is delay in callbacks

i'm using simple MVC structure by Nathan Broslawsky. 我正在使用Nathan Broslawsky的简单MVC结构。 i have these code below. 我下面有这些代码。

ArticleProviderDBController.prototype.Show = function(data) {
//Init Model
var res = this.Response;
var model = this.getModel();
var view = this.getView("ArticleProviderDB");

model.findAll(function(error, article_collections){
        if( error ) console.log(error);
        view.renderGH(res, data, article_collections); //this will actually call the renderGH function to serve a html file with data from DB but it is not working.
        res.write('inside callback'); //this will not.
        //res.end();
}); 
//console.log(_self.Response);
res.write('outside callback'); //this will be shown on my browser.
//res.end();

} }

actually i try to follow what people have done using expressjs 实际上,我尝试遵循人们使用expressjs所做的事情

app.get('/', function(req, res){
articleProvider.findAll( function(error,docs){
    res.render('index.jade', { 
        locals: {
            title: 'Blog',
            articles:docs
        }
    });
})

}); });

but seems like it is not working. 但似乎不起作用。

i also saw a post NodeJS response.write not working within callback posted recently but his solution is not working for me. 我还看到最近发布的NodeJS response.write在回调内不起作用,但他的解决方案对我不起作用。 My main objective is to use simple MVC structure created with Nodejs without the use of other templates such as expressjs to serve html with DB query. 我的主要目标是使用由Node.js创建的简单MVC结构,而不使用其他模板(如expressjs)通过数据库查询来提供HTML。 thank you. 谢谢。

I've failed to find a solution for the above question but i found a very nice nodejs mvc framework example created by davidpirek. 我未能找到上述问题的解决方案,但我发现了由davidpirek创建的一个非常不错的nodejs mvc框架示例。 The example given is working and very nice. 给出的示例工作正常,非常好。 i've make some minor changes so it can run on windows for my development. 我做了一些小的更改,以便可以在Windows上为我的开发运行。

http://www.nodejsmvc.com/ http://www.nodejsmvc.com/

many thanks to davidpirek. 非常感谢davidpirek。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM