Skip to content

Instantly share code, notes, and snippets.

@saarmstrong
Created October 19, 2013 19:51
Show Gist options
  • Save saarmstrong/7060684 to your computer and use it in GitHub Desktop.
Save saarmstrong/7060684 to your computer and use it in GitHub Desktop.
Example of a Cross Domain Angular GET request
var myApp = angular.module('angularAppApp', ['$httpProvider'])
.config(function ($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
function FetchCtrl($scope, $http, $templateCache) {
$scope.method = 'GET';
$scope.url = 'http://echo.jsontest.com/key/value/one/two';
delete $http.defaults.headers.common['X-Requested-With'];
$http({method: $scope.method, url: $scope.url, cache: $templateCache}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
}).
error(function(data, status) {
$scope.tasks = data || "Request failed";
$scope.status = status;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment