Angularjs 发布时没有console.log应答
前端Angularjs 发布时没有console.log应答,angularjs,ajax,console.log,Angularjs,Ajax,Console.log,前端 app.factory('CustomerService', function($http) { return { addCustomerToDb : function(customer) { return $http.post('localhost:4000/new_info', customer) .success(function(response) { //al
app.factory('CustomerService', function($http) {
return {
addCustomerToDb : function(customer) {
return $http.post('localhost:4000/new_info', customer)
.success(function(response) {
//alert(JSON.stringify(data))
console.log(response.customer)
});
// return $http({
// method:"POST",
// url: "localhost:4000/new_info",
// customer:customer
// });
}
}
});
app.controller("new_info", function($scope, CustomerService, $routeParams) {
$scope.register = function () {
CustomerService.addCustomerToDb($scope.customer)
.then(function(response) {
console.log(response.$scope.customer);
});
};
});
我猜是控制器中的
控制台.log
没有产生任何输出?响应
对象可能没有$scope
属性。如果更改console.log(response.$scope.customer),您会得到什么
到console.log(响应)代码>或console.log(response.customer)代码>?仍不显示任何内容在您工厂的控制台中。日志中是否显示任何内容?另外,我建议将.success
更改为。然后
,您需要返回响应对象。我想你可能吞咽了它,这就是为什么控制器没有返回任何内容。我尝试过。但是它仍然没有显示任何内容。它是$scope.register
甚至调用过吗?您是否在“浏览器网络”选项卡中看到该请求?