search

Home  >  Q&A  >  body text

node.js - 原生nodejs怎么把数据库里接收到的数据传给前端

萌新求教:
//执行查询

    connection.query('select * from newslist where sort=?', [sort], function (err, rs) {
        if (err) {
            console.log('[query] - :' + err);
            return;
        }
        console.log('--------------------------result----------------------');
        for (var i = 0; i < rs.length; i++) {
            console.log('The solution is: ', rs[i]);
        }
        console.log('--------------------------result----------------------');
    });

怎么把上面操作获取到的结果rs 传给前端(是用AJAX写的,上面代码仅仅是console.log可以在cmd控制台打出来)

伊谢尔伦伊谢尔伦2875 days ago427

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-17 16:09:48

    If it is passed to the front end through ajax, the relevant interface needs to be defined for the front end to access. Then put the operation of querying data in the interface. You can refer to my small project
    https://github.com/ermu592275...

    reply
    0
  • Cancelreply