简体   繁体   中英

Get data from Node.js via Express

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...

On the server-side my code is:

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

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)
});

Thank you for your help!

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);             
    });

});

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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