【问题标题】:express not rendering the html [duplicate]表达不呈现html [重复]
【发布时间】:2021-03-12 05:41:21
【问题描述】:

我正在尝试使用“.write”将信息发送回网页给用户,然后当我使用“.send”方法发送“.write”中存在的响应时,它不会呈现 html。

快递代码:-

 res.write("<h2>The weather seems like" + weatherDescription + "</h2>");
         res.write("<h1>The temprature in banglore is  " + temprature + " degree celcius.</h1><br>");
         res.send();

它是如何在浏览器中呈现的:

【问题讨论】:

标签: node.js api express backend


【解决方案1】:

您需要在写回 HTML 之前设置内容类型

res.set('Content-Type', 'text/html');

【讨论】:

    猜你喜欢
    • 2012-12-28
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2011-01-13
    • 1970-01-01
    • 2018-10-12
    相关资源
    最近更新 更多