如何使用 AngularJS 在 wp-api 中添加新评论?
How to add new comment in wp-api using AngularJS?
我想使用 angular js 向 WP-API 中的 wordpress post 添加新评论。这是我的职责:
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 无法进入错误块,之前有return 错误。这些是错误:
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)
由于 WP-API's github issues page,这是一个错误,将在 2.0 beta 13 版中解决。
对于下一个 Beta 版本之前的临时解决方案,我们可以在插件的 class-wp-rest-comments-controller.php
文件上应用 80dcacf 提交。
我想使用 angular js 向 WP-API 中的 wordpress post 添加新评论。这是我的职责:
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 无法进入错误块,之前有return 错误。这些是错误:
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)
由于 WP-API's github issues page,这是一个错误,将在 2.0 beta 13 版中解决。
对于下一个 Beta 版本之前的临时解决方案,我们可以在插件的 class-wp-rest-comments-controller.php
文件上应用 80dcacf 提交。