我正在尝试在 angularjs 1.3.15 中对跨站点域进行 AJAX 调用。我现在有一个标准的 AJAX 调用正在工作,但想改用 Angular 的 $http 配置元素。
我现在的 AJAX 调用:
var responsePromise = $.ajax({url:"https://some-address.com",
type: "GET",
dataType: "json",
xhrFields: {withCredentials:true},
crossDomain: true});
//my success and error functions
我用 $http(config) 尝试过的内容
var repsonsePromise = $http.get('/some-address.com',{reponseType:{json},
withCredentials:{'true'}});
//my .success and .error functions
我查看了 $http.get 服务 here
我应该为 crossDomain: true
参数添加什么,或者有人可以告诉我工作 AJAX 调用的等效语法才能使其正常工作吗?非常感谢您的帮助,先谢谢您。
最佳答案
试试这个:
app.config(function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
取自:http://samurails.com/tutorial/cors-with-angular-js-and-sinatra/
关于ajax - 如何使用 AngularJS $http 配置元素进行跨站点域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29887192/