I'm using expressjs. My issue is that a route is called again if, for some reason, I do not provide a response. In firebug, status of the request will be "pending". Eventually, after the route is called a second time, I get back a response ERR_EMPTY_RESPONSE
.
Here's a simple test:
// main.html
<html>
<body>
<span>test</span>
</body>
</html>
<script>
$.get("/test");
</script>
// app.js
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
app.get('/test', function(req, res) {
console.log("I'm called");
});
http.listen(3000, function() {
console.log('Express started');
});
You'll see I'm called
when you GET to the route, and then again after about 15-20 seconds.
It seems like Express or Node is somehow causing the route to run a second time. Why is this and how can it be prevented?
EDIT : Made a simple test demonstrating problem.
// main.html
<html>
<body>
<span>test</span>
</body>
</html>
<script>
$.get("/test");
</script>
// app.js
var express = require('express');
var app = express();
app.use(express.static(__dirname + '/public'));
app.get('/test', function(req, res) {
res.send("I'm called"); // you have to res.send() method
});
http.listen(3000, function() {
console.log('Express started');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.