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.

2
  • 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 Commented Apr 27, 2015 at 4: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 Commented Apr 27, 2015 at 4:30

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.