I am trying to use $HTTP method from angularJS to call my restful web service.
When I use my web service URL in browser I get result of APPLICATION/JSON type.
{"id":20418,"content":"Hello, World!"}
My webs service URL:
http://localhost:8082/vlinkRest/rest/employee/angular
But when I try to call my web service from angularJS within my HTML file, I get following error:
<?xml-stylesheet href="chrome://global/locale/intl.css" type="text/css"?>
<parsererror>
XML Parsing Error: not well-formed Location: chrome://browser/content/browser.xul Line Number 1, Column 1:
<sourcetext>{"id":20418,"content":"Hello, World!"} ^</sourcetext>
</parsererror>
This is my angularJS code:
function Hello($scope, $http) {
$http.get('http://localhost:8082/vlinkRest/rest/employee/angular', {headers: {'Accept': 'application/json'}}).
success(function(data) {
alert('0');
$scope.greeting = data;
}).error(function (data, status, headers, config) {alert('1:'+data+':'+status+":"+headers+":");});
}
If I am using following URL my code works fine:
http://rest-service.guides.spring.io/greeting
And when I run both the URL in the browser directly they display same result in the browser. Also I checked when running directly both produce output of type:
application/json
But for my web service when executed from angularJS code gives following error in HTTPFox:
00:00:01.387 1.154 423 168 OPTIONS 200 application/xml http://localhost:8082/vlinkRest/rest/employee/angular
When I run the URL directly in browser I get following:
00:00:40.067 0.166 319 110 GET 200 application/json http://localhost:8082/vlinkRest/rest/employee/angular
I'm probably doing something amateur but any help would be welcome!
Thanks