This is actually a problem on the server side. If the API is designed to be
used by applications not hosted on the server, it needs to be configured
with CORS (cross-origin resource sharing) headers to allow this.

The actual setup for doing that varies by server, but it's not too hard,
provided you can convince the server admin to do this.

e


On Wed, Aug 20, 2014 at 12:48 PM, Anubha Garg <[email protected]>
wrote:

> Hi,
>
> I am working on an application which needs to send a 'post' request to a
> server residing on a separate domain. The request and response data are of
> type XML. I tried using $http and $http.post methods, but it did not work.
> I get the following error message:
>
> "XMLHttpRequest cannot load "myUrl". No 'Access-Control-Allow-Origin'
> header is present on the requested resource. Origin 'http://localhost:1337'
> is therefore not allowed access. "
>
> After searching online and asking on the chatroom I came to know that
> these methods can only be used for JSON data.
>
> My Code currently looks like this :
>
> App.js:
> -------------
>
> angular.module('SmartZone', SmartZone.ModuleRegistry).
> config(function ($provide, $stateProvider, $urlRouterProvider,
> $httpProvider) {
> /*------------------Other Code ----------------------------------------*/
>         //Allow http requests outside the domain
>         $httpProvider.defaults.useXDomain = true;
>         delete $httpProvider.defaults.headers.common['X-Requested-With'];
> })
>
>
> Widget Controller:
> ----------------------------
>
> controller('Controller', ['$scope', 'dataManager', '$http',
> function($scope, dataManager, $http){
> /*------------------------------- Other Code
> -------------------------------------*/
>         $scope.url = "myUrl";
>         $scope.data = '<soapenv:Envelope xmlns:soapenv="
> http://schemas.xmlsoap.org/soap/envelope/";
> xmlns:sch="********************************************">'+
>             '<soapenv:Header>'+
>             '<sch:SmartNoteAuthentication>'+
>             '<sch:User>***********</sch:User>'+
>             '<sch:Password>*********</sch:Password>'+
>             '</sch:SmartNoteAuthentication>'+
>             '</soapenv:Header>'+
>             '<soapenv:Body>'+
>             '<sch:SmartNoteRequest>'+
>             '<sch:PatientNote>Headache & neck pain</sch:PatientNote>'+
>             '<sch:PatientDemographicInfo>'+
>
> '<sch:AgeRange><sch:Code>8</sch:Code><sch:Name>Adult</sch:Name></sch:AgeRange>'+
>
> '<sch:Gender><sch:Code>m</sch:Code><sch:Name>Male</sch:Name></sch:Gender>'+
>             '</sch:PatientDemographicInfo>'+
>             '<sch:ProcessType>NLP_And_DiffDiag</sch:ProcessType>'+
>             '</sch:SmartNoteRequest>'+
>             '</soapenv:Body>'+
>             '</soapenv:Envelope>';
>         alert($scope.url);
>         alert($scope.data);
>         $scope.config = "{ 'Content-Type': 'text/xml',
> 'Access-Control-Allow-Origin' : '*', 'Access-Control-Allow-Methods' :
> 'GET,POST', 'Access-Control-Allow-Headers' : 'Content-Type' }";
>         alert($scope.config);
>         $http({
>             method: 'POST',
>             url: $scope.url,
>             data: $scope.data,
>             headers: $scope.config
>         })
>             .success(function(data) {
>                 alert("http request was successful");
>                 alert("data is : "+data);
>                 alert("status is : "+status);
>             })
>             .error(function(data, status) {
>                 alert("http request failed");
>                 alert("data is : "+data);
>                 alert("status is : "+status);
>             });
>     }])
>
>
>  Can you tell me how I can achieve the above task? Kindly let me know if I
> need to provide any further information to help resolve this.
>
> Thanks,
> Anubha Garg
>
>  --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to