How to use AngularJS $ http config element for cross-site domain
I am trying to make an AJAX call in angularjs 1.3.15 for a cross-site domain. I have a standard AJAX call working now, but you want to use angular $ http config 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 can I supply for the argument, crossDomain: true
or can someone tell me the equivalent syntax of my working AJAX call to make this work? Your help is greatly appreciated, thank you for the advanced.
+3
source to share
1 answer
Try the following:
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/
0
source to share