user5620596
user5620596

Reputation:

api calling error in ionic-framework

I am getting this error:

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.

I have adde proxy url as show below:

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

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

Upvotes: 1

Views: 713

Answers (1)

Vikram Biwal
Vikram Biwal

Reputation: 2826

There is little mistake:

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

Upvotes: 1

Related Questions