使用 wordpress local env 的 Ionic V1 本地开发

Ionic V1 local develpment with wordpress local env

我有一个开发设置问题。

所以我有一个 Ionic 应用程序,我可以通过 运行 在本地 运行 简单地 运行ning: ionic serve

然后在应用程序的配置中,我将其指向 local.mysite.com(这是一个 wordpress 设置)。当我尝试登录时它会到达站点(在构造函数中设置的自定义端点插件中设置断点)但不会到达作为登录回调的函数。

我在控制台记录了哪个 URL $http.get(url).then 方法正在请求并在 url 中转到该登录并发生了预期的行为。

我主要是想知道这是否可行,以及是否有任何技巧可以让它发挥作用。

下面的工作代码示例 Ionic V1:

In your WordPress API file Add header:

header('Access-Control-Allow-Origin: *');
header( 'Access-Control-Allow-Headers: Authorization, Content-Type' );

您的Factory.js文件代码:

starter.factory('CommonFactory', function($http) { 
    var base= 'your api file url';
    return {
      //with POST data method        
        login_function: function(user, pass) {
            return $http({
                url: base,
                method: 'POST',
                headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                data: postData,
            });
        },

        // With GET data method
        login_function: function(user, pass) {
            return $http({
                url: base+ '?username='+user+'&password='+pass,
                method: 'GET',
                headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
            });
        },

      }
    });

您可以根据需要更改或重写它。

Controller.js

CommonFactory.login_function($scope.user,$scope.pass)
             .success(function(res) {
                // success handling
                 })
              .error(function(result) {
                //error handling
                 })

确保注入依赖。

我查看了本地环境的错误日志,发现问题是我从

收到了致命错误
PHP Fatal error: uncaught error: call to undefined function utf8_encode()

然后发现这个问题可以通过像这样安装php7.1-xml来解决

sudo apt-get install php7.0-xml
sudo service apache2 restart

(多亏了这个post