WP Rest API V2 CORS错误预检响应
问题描述:
我正在尝试开发一个与AngularJS一起使用WordPress进行管理的Web应用程序。我已经安装了WP和WP Rest API V2插件。我想通过Angular的$ http获得我的回复,并使用返回的数据。WP Rest API V2 CORS错误预检响应
我有我的工厂,看起来像这样:
(function() {
'use strict';
/**
* @ngdoc function
* @name app.service:prayersService
* @description
* # prayersService
* Service of the app
*/
angular
.module('prayers')
.factory('PrayersService', Prayers);
// Inject your dependencies as .$inject = ['$http', 'someSevide'];
// function Name ($http, someSevide) {...}
Prayers.$inject = ['$q', '$http'];
function Prayers ($q, $http) {
return{
get: function(){
return $http.get('https://drummerboyhosting.com/sandbox/rosary/wp-json/wp/v2/rosary_prayers/')
}
}
}
})();
所以,当我访问我的网站,并尝试登录我的本地主机的结果我得到这个错误:
XMLHttpRequest cannot load https://drummerboyhosting.com/sandbox/rosary/wp-json/wp/v2/rosary_prayers/. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers in preflight response.