var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope, $http) {
$scope.url = 'https://api.github.com';
$scope.debug = '';
$scope.test = function(method) {
$scope.debug = '...';
$http[method]($scope.url, {}, {
withCredentials: true
}).then(function(response) {
$scope.debug = 'SUCCESS:' + JSON.stringify(response);
}, function() {
$scope.debug = 'ERROR fetching data, check CORS support';
})
}
});
app.config(function($httpProvider) {
//$httpProvider.defaults.useXDomain = true;
})
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="angular.js@1.1.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js" data-semver="1.1.5"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<h3>CORS test</h3>
Saisissez une URL pour verifier que CORS fonctionne :
<br>
<input ng-model="url" size="50">
<button ng-click="test('get')">test GET</button>
<button ng-click="test('post')">test POST</button>
<hr>
<pre>{{ debug }}</pre>
</body>
</html>
/* Put your css in here */