簡體   English   中英

無法在http.get調用中從數據庫獲取數據

[英]can't get data from database on http.get call

嗨,我有一個問題,我不確定那是什么問題,我正在嘗試從http調用中從數據庫獲取數據並將其返回到前端。這就是我到目前為止

app.get('/contentHandler/post/frontPage', contentHandler.displayMainPage);

displayMainPage

 this.displayMainPage = function(req, res, next) {
        "use strict";
        posts.getPosts(10, function(err, result) { //the 10 is limit to 10 post
            "use strict";
            if(err) return next(err);
            res.send(200,result); // send it to front end 
        });
    }

getPosts

  this.getPosts = function(num, callback) {
        "use strict";
        posts.find().sort('date', -1).limit(num).toArray(function(err, items) {
            "use strict";

            if (err) return callback(err, null);

            console.log("Found " + items.length + " posts");

            callback(err, items);
        });


    }

前端(角度js控制器)

function IndexCtrl($scope, $http) {
  $http.get('/contentHandler/post/frontPage').
      success(function(data) {
        alert(data); // alert nothing/blank 
      }).error(function(err) {

      });


}

$ http * *之后刪除逗號(,)。 因為單個逗號不能幫助下一個過程:p哈哈

試試此代碼而不是您的代碼

function IndexCtrl($scope, $http) {
  $http.get('/contentHandler/post/frontPage').
      success(function(data) {
        alert(data); // alert nothing/blank 
      }).error(function(err) {

      });


}

刪除$ http之后的逗號(,),然后嘗試執行代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM