离子框架中的api调用错误 [英] api calling error in ionic-framework

查看:88
本文介绍了离子框架中的api调用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

XMLHttpRequest无法加载 http://example.com/user/api?action=user_info 。请求的资源上不存在Access-Control-Allow-Origin标头。因此,不允许访问来源 http://192.168.1.122:8100

XMLHttpRequest cannot load http://example.com/user/api?action=user_info. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.1.122:8100' is therefore not allowed access.

我有adde代理网址如下所示:

I have adde proxy url as show below:

{
    "name": "conference",
    "app_id": "",
    "proxies": [
                {
                    "path": "/api",
                    "proxyUrl": "http://example.com/user/api"
                }
            ]
}

调用api:

$http({
     method: 'POST',
     url: 'http://example.com/user/api?action=user_info',
     headers: {'Content-Type': 'application/x-www-form-urlencoded' }
}).success(function(data, status) {
     console.log('Got some data:  ', data);  
}).error(function(data, status) {
     console.log('Got some error:  ', data);
     console.log('Got some error:  ', status);
});


推荐答案

没有错误:

删除完整网址,如以下代码所示:

remove full url as show in below code:

$http({
      method: 'POST',
      url: '/api?action=login',
      headers: {'Content-Type': 'application/x-www-form-urlencoded' }
  }).success(function(data, status) {
     console.log('Got some data:  ', data);
  }).error(function(data, status) {
     console.log('Got some error:  ', data);
      console.log('Got some error:  ', status);
  });

这篇关于离子框架中的api调用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆