简体   繁体   English

在 Node.Js Express 中,“res.render”是否结束了 http 请求?

[英]In Node.Js Express, does “res.render” end the http request?

So, only do "res.render" when you are sure that everything has finished, right?所以,只有当你确定一切都完成时才执行“res.render”,对吗? Because it ends the request and shoots out a webpage.因为它结束了请求并弹出了一个网页。

If you don't provide a callback to res.render(view[, options[, fn]]) it will automatically give a response with 200 HTTP Status and Content-Type: text/html如果您不提供对res.render(view[, options[, fn]])的回调,它将自动给出 200 HTTP Status and Content-Type: text/html 的响应

res.render('view', {}, function() {
    while (true); // should block 
});

res.render(view[, options[, fn]]) res.render(view[, options[, fn]])

Render view with the given options and optional callback fn.使用给定的选项和可选的回调 fn 渲染视图。 When a callback function is given a response will not be made automatically, however otherwise a response of 200 and text/html is given.当回调 function 被给出时,不会自动做出响应,否则会给出 200 和 text/html 的响应。

express.js guide express.js 指南

With the current github master commit , this is res.render in lib/view.js :使用当前的github 主提交,这是lib/view.js 中的 res.render res.render

 /**
 * Render `view` with the given `options` and optional callback `fn`.
 * When a callback function is given a response will _not_ be made
 * automatically, however otherwise a response of _200_ and _text/html_ is given.
 *
 * Options:
 *  
 *  - `scope`     Template evaluation context (the value of `this`)
 *  - `debug`     Output debugging information
 *  - `status`    Response status code
 *
 * @param  {String} view
 * @param  {Object|Function} options or callback function
 * @param  {Function} fn
 * @api public
 */
res.render = function(view, opts, fn, parent, sub){
  // support callback function as second arg
  if ('function' == typeof opts) {
    fn = opts, opts = null;
  }

  try {
    return this._render(view, opts, fn, parent, sub);
  } catch (err) {
    // callback given
    if (fn) {
      fn(err);
    // unwind to root call to prevent
    // several next(err) calls
    } else if (sub) {
      throw err;
    // root template, next(err)
    } else {
      this.req.next(err);
    }
  }
};

暂无
暂无

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

相关问题 Node.js http.request使用单个res.render表达多个请求 - Node.js http.request Express multiple requests with single res.render Node.js和Express.js / Jade res.render返回res.render不是函数 - Node.js & Express.js/Jade res.render returns res.render is not a function node.js-Express:将参数发送到res.render() - node.js - Express: Sending parameters to res.render() Node.js res.render()与请求不起作用 - Node.js res.render() with Request not working 在Node.js Express服务器中处理GET请求:res.render(file.ejs,data)不起作用,因为未定义数据 - Handling a GET request in Node.js Express server: res.render(file.ejs, data) not working because data is not defined Node.js和Express应用程序中res.render()和ejs.render()之间的区别是什么 - What's the difference between res.render() and ejs.render() in Node.js and Express app Node.js / Express.js-如何覆盖/拦截res.render函数? - Node.js / Express.js - How to override/intercept res.render function? 如何在node.js(Express)中使用通过res.render传递的字典 - How to use dictionaries passed via res.render in node.js (Express) Node.js和Express:加载后更新router.get和res.render对象 - Node.js and Express: Updating router.get and res.render's object after load node.js - express - res.render():将变量提供给JSON参数的正确格式? - node.js - express - res.render() : Correct format for feeding variables into the JSON parameter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM