Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么node.js中的response.write没有注入html?_Javascript_Node.js - Fatal编程技术网

Javascript 为什么node.js中的response.write没有注入html?

Javascript 为什么node.js中的response.write没有注入html?,javascript,node.js,Javascript,Node.js,我正在学习《初学者节点》一书中的教程,我正在编写这段代码 var body = ' <html> <head> <meta http-equiv="Content-Type" content="text/html" charset="UTF-8"/> </head> <body> <form action="/upload" method="post"> <textarea name=

我正在学习《初学者节点》一书中的教程,我正在编写这段代码

    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();
var-body=
';
writeHead(200,{“内容类型”:“text/plain”});
答复.书面答复(正文);
response.end();
我已经把它隔开了,但我知道我需要把它全部放在一行上,当我这样做时,文本区域不会出现,所写的html会出现在屏幕上

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


怎么了

尝试更改此行:

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


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

“我想我需要将其全部放在一行上”-是的,或者将多个字符串连接在一起(每行一个)。你试过用
“text/html”
代替
“text/plain”
(在最后第三行)吗?是的,我知道,但我把它隔开了,以防我键入的html有问题……很好,这正是我想要的,但有一个问题,如果你这样做:res.writeHead(200,{“Content Type”:“text/html”});res.write('如何呈现/加载页面(视图)?

);res.write(“”);res.write('将加载(呈现)';res.write('localhost:'+port+'/products.html page/view');res.end();它不显示文本中写的http:。@MuhammadHannan-好吧,为什么要显示呢?您的字符串中没有包含“http:”。无论如何,这似乎与这个问题无关,所以也许你应该发布一个你自己的新问题。哇,谢谢@nnnn。我也有同样的问题!
response.writeHead(200,{"Content-Type" : "text/html"});