Created
October 19, 2013 19:51
-
-
Save saarmstrong/7060684 to your computer and use it in GitHub Desktop.
Example of a Cross Domain Angular GET request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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