1

I'm having some difficulties implementing a post request to my Spring Rest service running on localhost.

Now the request and the service both work, the current problem is that I keep receiving the same error, saying that my JSON is incorrect.

The code which I use for creating the JSON request:

$scope.addComment = function(){
var url = "http://localhost:8080/evenement/"+evenementId+"/deelnemers/"+deelnemer.id+"/addComment";
  $http.post(url, {"content" : $scope.data.comment, "author":"testUser"}).then(function(res){
    $scope.response = res.data;
    console.log(res.data);
  });
};

I tried removing the quotes, using single quotes and using no quotes, as answered on other questions with the same problem.


Request Payload as shown in Developer Console including errormessage.

9
  • 1
    So what is the exact string that is parsed? Commented Aug 10, 2016 at 6:59
  • Sounds like it is throwing a wobbly over the BOM - can you inspect the raw bytes received? Commented Aug 10, 2016 at 6:59
  • @Filburt I would like to but I do not know how, if you can show me what to do I can haha, Im using chrome fyi Commented Aug 10, 2016 at 7:02
  • @zerkms that probably will be {"content" : $scope.data.comment, "author":"testUser"} where the $scope.data.comment is replaced by a value out of a input field. Commented Aug 10, 2016 at 7:03
  • 2
    It is complaining about being unable to parse the response as JSON, which we're not seeing here. Commented Aug 10, 2016 at 7:16

1 Answer 1

3

The error message is telling you that it is unable to parse the response as JSON. Your server is not returning valid JSON to this request.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.