node问题
  • 板块学术版
  • 楼主Quenna
  • 当前回复0
  • 已保存回复0
  • 发布时间2023/5/17 18:19
  • 上次更新2023/10/23 15:30:47
查看原帖
node问题
697421
Quenna楼主2023/5/17 18:19

问题1

嗯......我写了上传的程序,但浏览器渲染报废了白屏(127.0.0.1)

response.writeHead(200, {'Content-Type': 'text/html'});
response.end(read("D:\\Warning!\\\123\\main.html"));

问题2

上代码 main.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>123</title>
		<style>
			#stu {
				position: absolute;
				width: 500px;
				height: 50px;
				top:225px;
				left: 500px;
				font-size: 50px;
				text-align: center;
				color: white;
				background-color: black;
			}
			#submit {
				position: absolute;
				width: 200px;
				height: 50px;
				top:300px;
				left: 650px;
				font-size: 30px;
				text-align: center;
				color: white;
				background-color: black;
			}
		</style>
	</head>
	<body>
		<form action="#" method="post">
			<input id="stu" type="text" placeholder="名称"/>
			<input id="submit" type="submit"/>
		</form>
	</body>
</html>

index.js

const http = require('http');
const fs = require("fs");
const url = require("url");
const querystring = require("querystring")
function read(path){
	fs.readFile(path, function (err, data){
	   if (err) {
	       return console.error(err);
	   }
	   return data.toString();
	});
};
function write(path,doing){
	fs.writeFile(path, doing,  function(err) {
	   if (err) {
	       return console.error(err);
	   }
	});
};
http.createServer(function (request, response) {
	const {query,pathname} = url.parse(request.url,true)
	const { method } = request
	if(method === "POST") {
		console.log('return html');
		if(pathname === "") {
			let getData = ""
			resquest.on("data", (data) => {
				getData += data;
			});
			resquest.on("end",() => {
				const data = qureystring .parse(getData);
				console.log(data);
			});
		}
	}else{
		response.writeHead(200, {'Content-Type': 'text/html'});
		response.end(read("D:\\Warning!\\123\\main.html"));
	}
}).listen(8888);
console.log('Server running at http://127.0.0.1:8888/');
2023/5/17 18:19
加载中...