Johno, I read through this discussion looking for an answer to your same
question and actually found the answer. A lot of people here gave you the
run around and suggested other solutions rather than answering your
original question which can be quite annoying.
This is how you will want to form your angular for resource.
angular.module('lookupService',
['ngResource']).config(function($httpProvider){delete
$httpProvider.defaults.headers.common['X-Requested-With'];})
.factory('lookupService', function ($resource) {
return $resource(lookupURL);
});
You will also need a CORS FILTER on the server side. I can show you how I
do it for my Java Rest Services.
I have attached a JAVA Cors Filter class that I use.
In your Web.xml you will want to add an <init-param> like the following.
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>package.ResponseCorsFilter</param-value>
</init-param>
The param-value is just the ResponseCorsFilter class location.
That should get you where you want to be. Cheers -Abe
On Wednesday, August 29, 2012 10:01:28 PM UTC-4, Johno Scott wrote:
>
> My html5 mobile app is running locally on a file:// URL on Android (using
> PhoneGap) so any call to a remote web service is going to be cross-domain.
>
> When I use $resource ( service in module ngResource ) to attempt a call to
> a remote endpoint :
>
> .factory('Order', ['$resource', '$http',
> function($resource, $http) {
> return $resource('http://example.com/api/orders/:_id',
> {}, {});
> }
> ])
>
> I get an error like this :
>
> XMLHttpRequest cannot load http://example.com/api/orders/ . Origin file://is
> not allowed by Access-Control-Allow-Origin.
>
> .. which I realise is your typical XHR cross-site security error.
>
> Is there an option to enable cross-domain support and relax this
> restriction ?
>
>
>
--
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/groups/opt_out.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mil.smil.jiatfs.southcom.rest.authentication;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;
/**
*
* @author asmith
*/
public class ResponseCorsFilter implements ContainerResponseFilter {
@Override
public ContainerResponse filter(ContainerRequest creq, ContainerResponse cresp) {
cresp.getHttpHeaders().putSingle("Access-Control-Allow-Origin", "*");
cresp.getHttpHeaders().putSingle("Access-Control-Allow-Credentials", "true");
cresp.getHttpHeaders().putSingle("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS, HEAD");
cresp.getHttpHeaders().putSingle("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With");
return cresp;
}
}