最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What cause "Error: Uncaught (in promise): Response with status:200 for Url:null" to show up? - St

programmeradmin2浏览0评论

I'm accessing a Mongo database through NodeJS and Express as below:

var MongoClient = require('mongodb').MongoClient;
    ...
    app.get("/app/visits", function (req, res, next) {
      console.log("get visits");
      MongoClient.connect('mongodb://localhost:27017/db', function (err, db) {
        if (!err) { console.log("We are connected"); }
        visits = db.collection('visits', function (err, collection) { });
        visits.find().toArray(function (err, user) {
          this.user = JSON.stringify(user);
          if (err) { throw err; } else console.dir(this.user);
        });
        res.send(this.user);
      });
    });

In the browser this works fine. If I change res.send(this.user); to res.status(301).send(this.user); the status is also changed. But the problem, Angular 2 with native script code returns the error:

getActualVisits()
     {  
        return this.http.get("http://localhost:1234/app/visits").map(response => response.json())
      }

I have no idea WHY after 7 hours of trying repair that. Method getActualVisits() is calling from:

 getActualSpecialization() {
    let v = this.getActualVisits();
...
}

I'm accessing a Mongo database through NodeJS and Express as below:

var MongoClient = require('mongodb').MongoClient;
    ...
    app.get("/app/visits", function (req, res, next) {
      console.log("get visits");
      MongoClient.connect('mongodb://localhost:27017/db', function (err, db) {
        if (!err) { console.log("We are connected"); }
        visits = db.collection('visits', function (err, collection) { });
        visits.find().toArray(function (err, user) {
          this.user = JSON.stringify(user);
          if (err) { throw err; } else console.dir(this.user);
        });
        res.send(this.user);
      });
    });

In the browser this works fine. If I change res.send(this.user); to res.status(301).send(this.user); the status is also changed. But the problem, Angular 2 with native script code returns the error:

getActualVisits()
     {  
        return this.http.get("http://localhost:1234/app/visits").map(response => response.json())
      }

I have no idea WHY after 7 hours of trying repair that. Method getActualVisits() is calling from:

 getActualSpecialization() {
    let v = this.getActualVisits();
...
}
Share Improve this question edited Jan 1, 2021 at 2:25 d-cubed 1,1127 gold badges31 silver badges62 bronze badges asked Jul 22, 2016 at 14:10 Tomasz.STTomasz.ST 1432 gold badges2 silver badges7 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You need to call .subscribe after .map in order to observe the values that are returned.

getActualVisits() {  
    return this.http.get("http://localhost:1234/app/visits")
        .map(response => response.json())
        .subscribe(
            data => this.actualVisits = data,
            err => this.logError(err),
            () => console.log('get actual visits plete')
         );
}

See the following docs for more information https://auth0./blog/2015/10/15/angular-2-series-part-3-using-http/

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论