问题描述
在这里,我无法在节点服务器中打印控制台代码console.log("I got the data I requested");
here I am unable to print my console code console.log("I got the data I requested");
in my node server
浏览器控制台中显示的错误在下图中
the error that is displayed in the browser console is in the image below
这是server.js的代码
here is the code of server.js
var express = require('express');
var app = express();
app.use(express.static(__dirname + "/public"))
app.listen(3000);
console.log("server running on port 3000")
这是controller.js的代码
here is the code of controller.js
var app = angular.module('myApp', []);
app.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
console.log("Hello World from controller");
$http({
method: 'GET',
url: '/employeelist'
}).then(function (response) {
console.log("I got the data I requested");
$scope.employeelist = response.data;
});
employee1 = {
name: 'Sunil',
designation: 'Software Developer',
salary: '20000'
};
employee2 = {
name: 'Vamshi',
designation: 'Java Developer',
salary: '30000'
};
employee3 = {
name: 'Chethan',
designation: 'Dot Net Developer',
salary: '20000'
};
var employeelist = [employee1, employee2, employee3];
$scope.employeelist = employeelist;
}]);
我试图在我的节点服务器中打印控制台代码
I trying to print the console code in my node server
我无法在此处打印我的console.log(")
i am unable to print my console.log("") here
推荐答案
我已经更改了server.js和controller.js代码,现在如果我打开本地主机,我可以收到一个获取请求
i have changed the server.js and controller.js codes and now if I open the localhost I can a receive a get request
这是我所做的更改
server.js
server.js
var express = require('express');
var app = express();
app.use(express.static(__dirname + "/public"));
app.get("/employeelist", function (req,res) {
console.log("I received a GET Request")
employee1 = {
name: 'Sunil',
designation: 'Software Developer',
salary: '20000'
};
employee2 = {
name: 'Vamshi',
designation: 'Java Developer',
salary: '30000'
};
employee3 = {
name: 'Chethan',
designation: 'Dot Net Developer',
salary: '20000'
};
var employeelist = [employee1, employee2, employee3];
res.json(employeelist);
});
app.listen(3000);
console.log("server running on port 3000");
controller.js
controller.js
var app = angular.module('myApp', []);
app.controller('AppCtrl', ['$scope', '$http', function($scope, $http) {
console.log("Hello World from controller");
$http({
method: 'GET',
url: '/employeelist'
}).then(function onSuccess(response) {
console.log("data recieved");
$scope.employeelist=response.data;
},function onError(error) {
console.log("Unknown error");
$scope.employeelist=error.data;
});
}]);
index.html
index.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<title>Employees List</title>
</head>
<body>
<div class="container" ng-controller="AppCtrl">
<h1>Employees List</h1>
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Designation</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="employee in employeelist">
<td>{{employee.name}}</td>
<td>{{employee.designation}}</td>
<td>{{employee.salary}}</td>
</tr>
</tbody>
</table>
</div>
<script src ="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/
angular.min.js"></script>
<script src="../../controllers/controller.js"></script>
</body>
</html>
这篇关于可能未处理的HTTP请求拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!