angular jsを使用してWP-APIのwordpressの投稿に新しいコメントを追加したいと思います。そして、これはそれを行うための私の機能です:
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);
});
}
しかし、それは正しく動作しません。この方法で新しいコメントを追加するにはどうすればよいですか?
UPD #1 angular はエラー ブロックに入り、その前にエラーを返すことができないようです。これらはエラーです:
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)