通过前preSS获取来自Node.js的数据 [英] Get data from Node.js via Express

查看:125
本文介绍了通过前preSS获取来自Node.js的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Node.js的服务器和我用防爆preSS构建Web应用程序。 我的服务器已经能够得到从使用函数(rss_interrogDB)的数据库的阵列。现在,我想用这个数组来显示在HTML页面的列表。但我必须失去了一些东西......

I have a server with Node.js and I use Express to build a web app. My server is already able to get an array from a database using a function (rss_interrogDB). Now I want to use this array to display a list in the html page. But I must be missing something...

在服务器端我的code是:

On the server-side my code is:

app.get('/', function(req, res) { 
rss_interrogDB(function() {
// don't konw what to add here
});

在HTML页面中的code是:

On the html page the code is:

$.get('/', {}, function(data){
// not sure it is the right code
console.log(data);
// then the code to create a list from the array (no pb with that)
});

感谢您的帮助!

推荐答案

假设你的数据库给你数据的数组,加入这样的事情到你的服务器code:

Assuming your DB gives you an array of data, add something like this to your server code:

app.get('/', function(req, res) { 

    rss_interrogDB(function(serverData) {
        res.send(serverData);             
    });

});

您可以操纵serverData对象,并建立一个在你面前它发回更适合于客户,但是这取决于你想做的事情。

You could manipulate the serverData object and build one that is more suitable for the client before you send it back, but that depends on what you want to do.

这篇关于通过前preSS获取来自Node.js的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆