[英]How do I send post data to my server side node.js application?
I have a server side node js application which sends me all of the facebook posts from a specified page since a desired date. 我有一个服务器端节点js应用程序,自期望日期以来,该应用程序将指定页面上的所有facebook帖子发送给我。
Up until now I have been running the application on my terminal using npm start [facebook page name] [sinceDate]
. 到目前为止,我一直在使用
npm start [facebook page name] [sinceDate]
在终端上运行该应用程序。
Now that my app is running smoothly I would like to add some front end into the mix. 现在我的应用程序运行顺利,我想添加一些前端。 On an index.html page (located at
app/views/index.html
) I have created an input form which takes in the facebook page name
and sincedate
arguments. 在index.html页面(位于
app/views/index.html
)上,我创建了一个输入表单,该表单接受了facebook page name
和sincedate
参数。
I was wondering if anyone had any advice on how to send this post
data to my server side node application? 我想知道是否有人对如何将此
post
数据发送到服务器端节点应用程序有任何建议?
Here's a list of my dependencies, let me know if there's anything I need to elaborate on: 这是我的依赖项列表,让我知道是否需要详细说明:
"dependencies": {
"aws-sdk": "^2.7.10",
"express": "^4.14.0",
"request": "^2.79.0",
"request-promise": "^4.1.1"
},
You can send post notification using Ajax call. 您可以使用Ajax呼叫发送帖子通知。
$.ajax({
url: "/your/controller",
data: myData,
dataType: "json",
cache: false,
}).success(function (result) {
// Do something with responce
});
So, next step is to make route on node.js server side for incoming requests. 因此,下一步是在node.js服务器端建立路由以接收传入请求。 For example:
例如:
var express = require('express');
var app = express();
var router = express.Router();
app.use('/your/controller', {
router.post('/', function (req, res, next){
var requestedData = req.body.myData;
res.status(200).end();
});
});
Hope this help. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.