Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用AngularJS在wp api中添加新注释?_Angularjs_Wordpress_Wp Api - Fatal编程技术网

如何使用AngularJS在wp api中添加新注释?

如何使用AngularJS在wp api中添加新注释?,angularjs,wordpress,wp-api,Angularjs,Wordpress,Wp Api,我想使用angular js在WP-API中为wordpress的帖子添加新的评论。这就是我的职责: WPService.setComment = function(comment) { var data = [ { 'author_email' : comment.email, 'author_name' : comment.name, 'author_url' : comment.ur

我想使用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)
SyntaxError:意外标记<
at Object.parse(本机)
在fromJson(http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:1271:14)
在defaultHttpResponseTransform中(http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:9460:16)
在http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:9551:12
在弗雷赫(http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:340:20)
在transformData(http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:9550:3)
在转换响应时(http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:10319:21)
在进程队列中(http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:14792:28)
在http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:14808:27
在范围内。$eval(http://localhost/wordpress/wp-content/themes/theme1/bower_components/angular/angular.js?ver=4.4.2:16052:28)
由于,这是一个缺陷,将在2.0 beta 13版中解决。
对于下一个beta版之前的临时解决方案,我们可以在插件的
class wp rest comments controller.php
文件上应用commit。

您有任何错误吗?我想您的
wp api
代码没有返回正确的响应。.我想您是对的。因为我一个接一个地注释掉了参数,并且在发送
post
参数时得到了错误。我想我应该在github项目上报告这一点。现在我发现提交的评论是正确的,但是我得到了那个错误。为什么?因为在电话里你通常会得到回复。。似乎该响应的格式不正确。。你能分享你的评论api代码吗?