3

i have a spring method in my controller that has a String type return result when i consume The Web Service by Angular ($http) i get

SyntaxError: Unexpected token a at Object.parse (native)

this is my controller

@RequestMapping(value = "/api/loggeduser",method=RequestMethod.GET, produces =MediaType.APPLICATION_JSON_VALUE )
public ResponseEntity<String> findMessagesForUser(Principal principal) {
    System.out.println("looged user login="+principal.getName());
        return new ResponseEntity<String>(principal.getName(), HttpStatus.OK);

}

and this my Angular Function :

$http.get("http://localhost:8080/projet/rest/users/api/loggeduser").success(function(data) {
     console.log(data);      
})

2 Answers 2

3

The media type of the response is MediaType.APPLICATION_JSON_VALUE therefore Angular tries to parse the response data as JSON and this fails. Use MediaType.TEXT_PLAIN_VALUE instead.

Sign up to request clarification or add additional context in comments.

Comments

2

Use it like this angular won't recognize what type of data you sending so try sending it with double quote to escape double quote use the antislash or you can change mediaType to text plain

String name=" \" "+principal.getName()+" \" ";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.