gpt4 book ai didi

javascript - 为什么 node.js 中的 response.write 不注入(inject) html?

转载 作者:搜寻专家 更新时间:2023-11-01 00:10:02 25 4
gpt4 key购买 nike

我正在学习初学者 Node 书中的教程并输入这段代码。

    var body = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/>
</head>

<body>
<form action="/upload" method="post">
<textarea name="text" rows="20" cols="60"></textarea>
<input type="submit" value="Submit text"/>
</form>
</body>
</html>';
response.writeHead(200,{"Content-Type" : "text/plain"});
response.write(body);
response.end();

我已经把它分开了,但我知道我需要把它全部放在一行上,当我这样做时,textarea 不会出现,所写的 html 会出现在屏幕上。

我把它隔开了,因为我不确定 html 是否正确。

怎么了?

最佳答案

尝试改变这一行:

response.writeHead(200,{"Content-Type" : "text/plain"});

收件人:

response.writeHead(200,{"Content-Type" : "text/html"});

(您希望浏览器将其解释为 html,而不是纯文本。)

关于javascript - 为什么 node.js 中的 response.write 不注入(inject) html?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14413559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com