http://expressjs.com/
服务器上大致是这样的:
var app = express.createServer();
app.use(express.bodyParser());
app.post('/search', function(req, res){
search_form = req.body; // <-- search items
MySearch.doSearch(search_form,function(err,items) {
res.send(items);
});
});
app.listen(3000);
您将必须实现 doSearch 代码以返回您正在搜索的任何内容......
客户:
<script>
$.ajax( {
url: '/search',
data: search_form,
type: 'POST',
success: function(items) {
/* do something with items here */
// You will likely want a template so you don't have to format the string by hand
for( var item in items ) {
$('#results').append('<div>'+item.interestingField+'</div>);
}
}
});
</script>