Ionic V1本地开发与wordpress本地环境

时间:2017-05-11 17:22:37

标签: wordpress api ionic-framework config

我有一个开发设置问题。

所以我有一个Ionic应用程序,只需运行即可在本地运行: ionic serve

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

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

我主要只是寻找一个答案,看看是否可行以及是否有任何技巧可以让它发挥作用。

2 个答案:

答案 0 :(得分:0)

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

  

在WordPress API文件中添加标题:

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
                 })

确保注入依赖。

答案 1 :(得分:0)

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

那里得到致命错误
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

(感谢此帖utf8_(en|de)code removed from php7?

相关问题