【问题标题】:Ionic V1 local develpment with wordpress local envIonic V1 本地开发与 wordpress 本地环境
【发布时间】:2017-10-10 20:15:31
【问题描述】:

我有一个开发设置问题。

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

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

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

我主要只是在寻找关于这是否可能以及是否有任何技巧可以使其发挥作用的答案。

【问题讨论】:

标签: wordpress api ionic-framework config


【解决方案1】:

我查看了本地环境的错误日志,发现问题是我收到了来自

的致命错误
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?

【讨论】:

    【解决方案2】:

    下面带有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
                     })
    

    确保注入依赖项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-28
      • 2017-04-07
      • 1970-01-01
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2019-05-03
      • 1970-01-01
      相关资源
      最近更新 更多