Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

HI i have a micro service running on port 8501.

@RestController
@RequestMapping("/feeds")
public class FeedsController {

    @RequestMapping(method = GET)
    ResponseEntity<?> findAllFeeds() {
        return new ResponseEntity<String>("Hello", OK);
    }


}

when i add url http://localhost:8501/feeds, browser displays "Hello". Now i am trying to access this through angularjs get call

in my AngularJs my code is

'use strict';

var app = angular.module('commentsjsApp');
app.controller('MainCtrl', function ($scope,$http) {

    $http.jsonp('http://localhost:8501/feeds').success(function(data, status, headers, config){
    console.debug("Data : "+data+ "Status");
}).error(function(){
    console.debug("error");
});

EDIT : In Network tab (firebug) i can see the GET with 200 status and response is "Hello". Why i am getting the error in console then? Can any one kindly help me.

and when i run this angularjs app. the following output on console as shown in image

enter image description here

share|improve this question
 
If your html page is not being served from localhost:8501, then I think you are running against restrictions on fetching data across domains. You may need CORS or jsonp to transfer your data. –  musically_ut Dec 11 '13 at 8:09
 
@musically_ut thanks for response, i have now updated my question. can you kindly check it now –  Shahzeb Dec 11 '13 at 8:46
add comment

2 Answers

Sometimes Angular requires the colon in the URL to be quoted, try this:

$http.get('http://localhost\\:8501/feeds').success(function(data, status, headers, config){
        console.debug("Data : "+data);
    }).error(function(){
        console.debug("error");
    });
share|improve this answer
 
i have updated my question. Kindly check it. thanks –  Shahzeb Dec 11 '13 at 8:46
 
You can try to return properly formatted JSON from server, something like return new ResponseEntity<String>("{value: 'Hello'}", OK);. –  remigio Dec 11 '13 at 15:14
add comment

You are requesting a JSONP data, but the server is returning a string. Return a proper JSON object from the server to fix the issue.

Note: Hello world is not valid JSON, but "Hello World" is.

share|improve this answer
 
I have Updated the question, as i can see the "Hello" in response (when check it in the network tab of firebug) –  Shahzeb Dec 11 '13 at 13:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.