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 want to add new comment to wordpress's post in WP-API using angular js. And this is my function to do that:

WPService.setComment = function(comment) {
    var data = [
        {
            'author_email'  : comment.email,
            'author_name'   : comment.name,
            'author_url'    : comment.url,
            'content'       : comment.body,
            'post'          : comment.post
        }
    ];
    return $http.post('wp-json/wp/v2/comments', data[0]).success(function(res, status, header) {
        console.log('comment posted...!');
    }).error(function(err) {
        console.error(err);
    });
}

But it doesn't work properly. How can I add new comment in this way?

UPD #1 It seems angular can't enter to error block and return errors before that. These are errors:

SyntaxError: Unexpected token <
at Object.parse (native)
at fromJson (http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:1271:14)
at defaultHttpResponseTransform (http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:9460:16)
at http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:9551:12
at forEach (http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:340:20)
at transformData (http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:9550:3)
at transformResponse (http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:10319:21)
at processQueue (http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:14792:28)
at http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:14808:27
at Scope.$eval (http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:16052:28)
share|improve this question
    
did you get any error? – Minato 20 hours ago
    
oops I forgot to put errors, I updated the question. – bobsilon 20 hours ago
1  
I guess your wp-api code is not returning a proper response.. – Minato 20 hours ago
    
I think you right. Because I commented out parameters one by one and I get the errors just when I send post parameter. I think I should to report this on github project. – bobsilon 18 hours ago
    
Now I find that the comment submitted properly, But angular get that error. Why? – bobsilon 18 hours ago

Due to WP-API's github issues page, This was a bug which will be resolve in version 2.0 beta 13. For temporary solution before next beta release we can apply the 80dcacf commit on class-wp-rest-comments-controller.php file of the plugin.

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.