Я не получаю данные от ответа веб-службы в angularjs с использованием метода $ http.get.Что причина? Он напрямую переходит в часть ошибки.Angularjs and Web service Issue
Web код услуги:
@GET
@Path("/getEmployeeList")
@Produces(MediaType.APPLICATION_JSON)
public Response getEmployeeList() {
ArrayList<Employee> empList = (ArrayList<Employee>) employeeService.getAllEmployees();
return Response.status(200).entity(empList).build();
}
Угловая Js:
<script src="angular.js"></script>
</head>
<body >
<div ng-app="hello">
<h1>Greeting</h1>
<div ng-controller="home" >
<div ng-repeat="a in greeting">
<p>The Id is: {{a.empId}}</p>
<p>The content is: {{a.firstName}}</p>
<p>The content is: {{a.lastName}}</p>
</div>
</div>
</div>
</body>
<script >
var myApp = angular.module('hello', []);
myApp.controller('home',['$scope','$http',function($scope,$http) {
$http.get("http://localhost:8080/restful-jersey-spring-demo/restws/employee/getEmployeeList")
.success(function(data) {
$scope.greeting = data;
}).error(function(data, status, headers, config){
alert("Error")
});
}]);
</script>
</body>
Json данных из веб-служб: URL: http://localhost:8080/restful-jersey-spring-demo/restws/employee/getEmployeeList
[
{
"empId": 1,
"firstName": "Chirag",
"lastName": "L"
},
{
"empId": 2,
"firstName": "Prashant",
"lastName": "K"
}
]
сведения об ошибке console.info или поместить ваш браузер в режиме разработчика, чтобы получить подробную информацию об ошибке. Я подозреваю использование абсолютного uri. Вы пытались использовать этот «/ restful-jersey-spring-demo/restws/employee/getEmployeeList»? – boly38
Я получаю следующее Ошибка: запрос на перекрестный запрос заблокирован: политика одинакового происхождения запрещает чтение удаленного ресурса по адресу http: // localhost: 8080/restful-jersey-spring-demo/restws/employee/getEmployeeList. (Причина: заголовок CORS «Access-Control-Allow-Origin» отсутствует). – Vivek
Согласно CORS, другой порт имеет другое происхождение. Вам нужно убедиться, что ответ Джерси включает заголовок Access-Control-Allow-Origin: *. –