我的应用程序只是简单地接受输入并将其存储在一个数组中,然后将其删除,但这是我按顺序输入 1234567890 时得到的
Express server listening on port 3000
1 1
0
12 1
0
123 1
0
1234 1
0
12345 1
0
123456 1
0
然后它会在显示此之前停止大约 3 分钟
1234567 1
0
12345678 1
0
123456789 1
0
1234567890 1
0
为什么会停止?似乎有某种超时发生,或者有某种监听器我没有正确处理
var express = require('express')
, http = require('http')
, path = require('path')
, fs = require('fs');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
var queries = new Array();
function printAndShiftArray() {
console.log(queries + " " + queries.length);
if (queries.length == 0) {
console.log("array is empty");
} else {
queries.shift();
}
console.log(queries + " " + queries.length);
}
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
app.post('/search', function(req, res) {
input = req.param('letter');
queries.push(input);
printAndShiftArray();
});
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
用这个调用 /search api
$(document).ready(function() {
$('#letter').on("keyup", function() {
letter = $('#letter').val();
$.post("/search", { letter: letter}, function(data) {
$('#status').html(data);
});
});
});