gpt4 book ai didi

javascript - 在node.js上显示html

转载 作者:行者123 更新时间:2023-12-03 06:08:36 25 4
gpt4 key购买 nike

我是nodejs新手。我正在尝试通过nodejs显示html表单,这是我的代码:

function start(response){
console.log("Request handler 'start' was called.");
var body = '<html>\n'+
'<head>\n'+
'<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();
}

问题是当我运行代码服务器时只需给我 html 源检查图像:

enter image description here

我的问题出在哪里?

最佳答案

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

您已经告诉浏览器您正在向其发送纯文本,因此它会将文档呈现为纯文本。

如果您要发送 HTML,请说它是 HTML。

Content-Type: text/html

关于javascript - 在node.js上显示html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39424464/

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