Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have a Web API controller that looks like this:

    [HttpPost]
    public IHttpActionResult Test()
    {
        return Ok();
    }

This is correct syntax, However when I try to call this from a service in Angular 2, I get the error message: "json parsing error syntax error unexpected end of input." To resolve this issue, I have to put a value into the ActionResult such as

return Ok(1)

Am I missing some configuration? My Angular 2 service call looks like this:

return this.http.post(API/Controller/Test).map(res => res.json());

share|improve this question
up vote 2 down vote accepted

I guess that when you receive an empty response (without payload) you don't need to call the json method. Under the hood, the XHR response is undefined, JSON.parse(undefined) is called and an error is thrown.

You could skip the call of the map operator:

return this.http.post(API/Controller/Test)/*.map(res => res.json())*/;
share|improve this answer

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.