简体   繁体   English

如何使用Express,Javascript和Handlebars在POST请求中显示URL数据?

[英]How to display the URL data in a POST Request using Express, Javascript & Handlebars?

How would I go about utilizing a POST request to display the URL data like a GET request? 我将如何利用POST请求像GET请求一样显示URL数据? For example I'm trying to have the URL " http://localhost:8000/requestPost?hello=goodbye&numbers=123 " print the following list - 例如,我正在尝试使URLhttp:// localhost:8000 / requestPost?hello = goodbye&numbers = 123 ”打印以下列表-

  • hello - goodbye 你好再见
  • numbers - 123 数字-123

How would I go about getting access to the URL variables with a POST ? 我将如何通过POST访问URL变量? I'm using Express & Handlebars. 我正在使用Express&Handlebars。

You would do it the same way as you would for a get request: 您将执行与获取请求相同的方法:

var express = require('express');
var app = express();

app.post('/requestPost', function(req, res){
  res.send('hello: ' + req.query.hello + ' numbers: ' + req.query.numbers);
});

app.listen(3000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM