-
-
Save yihangho/c2b78ec9edf69868b0e1 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Rails CORS</title> | |
</head> | |
<body ng-app="app"> | |
<div ng-controller="PostController"> | |
<ul> | |
<li ng-repeat="post in posts">{{ post }}</li> | |
</ul> | |
Delete status: {{ deleteStatus }}. | |
</div> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js"></script> | |
<script> | |
var app = angular.module('app', []); | |
app.controller('PostController', ['$scope', '$http', function($scope, $http) { | |
$scope.deleteStatus = "ongoing"; | |
$http.get('http://localhost:3000/posts.json').success(function(data) { | |
$scope.posts = data; | |
}).error(function() { | |
console.log("Error getting posts") | |
}); | |
$http.delete('http://localhost:3000/posts/1.json').success(function(){ | |
$scope.deleteStatus = "done"; | |
}).error(function() { | |
$scope.deleteStatus = "error"; | |
}); | |
}]); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm getting exactly the same CORS error. Running rails sever on port 3000, running an http-server on port 8080 on Chrome, this code doesn't work.
edit: same thing on Firefox