3

I am trying to make an AJAX call in angularjs 1.3.15 to a cross-site domain. I have a standard AJAX call working now but would like to use angular's $http config element instead.

my AJAX call now:

var responsePromise = $.ajax({url:"https://some-address.com",
                              type: "GET",
                              dataType: "json",
                              xhrFields: {withCredentials:true},
                              crossDomain: true});
                              
                              //my success and error functions

what I tried with $http(config)

var repsonsePromise = $http.get('/some-address.com',{reponseType:{json},
                                                     withCredentials:{'true'}});

//my .success and .error functions

I have looked at the $http.get service here

What do I put for the crossDomain: true argument or is could someone tell me the equivalent syntax of my working AJAX call in order for this to work? Your help is greatly appreciated, thank you in advanced.

Community
  • 1
  • 1
Brad1100
  • 33
  • 1
  • 5
  • jQuery's `crossDomain` is only useful for forcing a cross-domain request on the same domain. If the remote site is set up for CORS, you shouldn't have to do anything. If it's a JSONP service, use [`$http.jsonp`](https://docs.angularjs.org/api/ng/service/$http#jsonp) – Phil Apr 27 '15 at 04:28
  • Also, if it really is a cross-domain request, the URL used in Angular will have to be fully qualified, ie `https://some-address.com/whatever` – Phil Apr 27 '15 at 04:30

1 Answers1

0

Try this:

app.config(function($httpProvider) {
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
});

Taken from: http://samurails.com/tutorial/cors-with-angular-js-and-sinatra/

Sharn White
  • 624
  • 3
  • 15