<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Password - form</title>
</head>
<body>
<form>
<label>Password</label>
<input type="password" id="passid" />
<br>
<input type="submit" value="Sign In" />
<!-- We also have input type = "button" and events for both >>> onsubmit & onclick. -->
</form>
<script>
function passType() {
let p = frm.querySelector('#passid');
let pass = p.value;
var password = ["p1", "p2", "p3", "p4", "p5"];
if (password.indexOf(pass) > -1) {
alert("That's great! Thank you!");
} else {
alert("Wrong, try again");
if (password.indexOf(pass) > -1) {
alert("It's wrong, you have one more try...");
} else {
alert("Get out now!");
window.close();
}
}
}
let frm = document.querySelector('form');
frm.addEventListener('submit', passType);
</script>
</body>
</html>
使用此代码,我可以接收请求,但我无法回复。它显示var url = require('url');
var http = require('http');
http.createServer(function (req, res) {
var url_parts = url.parse(req.url, true);
var q = url_parts.query;
console.log(q.query);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify({ a: 1 }));
console.log(q.query);
}).listen(8080);
答案 0 :(得分:12)
您需要res.end
代替res.send
。 res.send
是express
模块的一部分,而不是核心http module
的一部分。