在尝试发布到mongodb时,我对来自angularjs的挂起$ http.post请求有疑问。 我的app.js:
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.static(__dirname + '/public'));
app.use('/bower_components', express.static(__dirname + '/bower_components'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.methodOverride());
app.use(app.router);
我的路线:js for post:
self.routeTable.push({
requestType : 'post',
requestUrl : '/getAllPrjProjections',
callbackFunction : function (request, response) {
console.log(request.body.pr_code);
console.log(request.body.high_low);
console.log(request.body);
var prjProjectionsDao = require('../Server/Dao/prjProjectionsDao.js');
prjProjectionsDao.create({
pr_code : request.body.pr_code,
high_low : request.body.high_low,
subs_rate : request.body.subs_rate,
prj_month : request.body.prj_month,
prj_value : request.body.prj_value,
last_saved : request.body.last_saved
}, function(err, todo) {
console.log(todo);
if (err) {
console.log('bbb');
response.send(err);
}
});
}
});
在控制器中,当用户单击saveProjections按钮时,我实现了以下功能:
$scope.saveProjections = function() {
$scope.prj_to_save = {"pr_code":"PGU","high_low":"HIGH","subs_rate":"Paid Subs","prj_month":"2016-10-01","prj_value":"96000","last_saved":"2016-12-07"};
var data_to_send = JSON.stringify($scope.prj_to_save);
prjProjectionsService.saveProjections($scope.prj_to_save).then(function(success) {
// $scope.formData = {};
console.log(data, 'Blog created.');
},function (error) {
console.log("The request failed: " + error.data);
});
};
注入的服务器如下:
function saveProjections(prjData){
return $http.post('/getAllPrjProjections', prjData).then(function (success) {
console.log('success');
}, function (error) {
console.log('error');
});
}
问题是请求长时间处于挂起状态(附加的版画屏幕),然后失败并显示错误:" XMLHttpRequest:网络错误0x2ef3,由于错误00002ef3"
无法完成操作但是,数据发布在mongodb中。 你能帮帮我吗?我将不胜感激。
答案 0 :(得分:0)
您只是在发生错误时发送回复,所以在成功的情况下也会发送内容
object