0
我的NodeJs應用程序在這個url中返回(http://localhost:3000/api/campaigns)一個json響應。NodeJS在Angular中的空回收
但是當我的Angular應用程序調用這個URL時,得到一個空的響應。 我嘗試將200
http代碼更改爲404
,並且我看到此更改,但始終存在ara空的響應。
角:
var campaigns = function(country) {
var deferred = $q.defer();
$http.get("http://localhost:3000/api/campaigns").then(function(response) {
deferred.resolve(response);
}, function(response) {
deferred.reject(response);
});
return deferred.promise
}
在我的代碼的NodeJS:
exports.findAllCampaigns = function(req, res) {
Campaign
.find({})
.limit(10)
.exec(function(err, campaigns) {
if(err) res.send(500, err.message);
res.status(200).jsonp(campaigns);
});
};
在我的瀏覽器控制檯中,XHR request
總是空(http 200
)。
它的'jsonp'調用?那麼你爲什麼要進行'.get'調用。我認爲你應該使用'callback:params'作爲'$ http.get'來做:'JSON_CALLBACK' –
不應該是'res.send(campaigns)'或'res.send(JSON.stringify(campaigns))'正確的內容類型標題?或者是jsonp的包裝呢? – maurycy
我嘗試將'jsonp'更改爲'send'。返回相同的空響應,但將標題content-type =「application/json」更改爲「text/html」 –