我注意到 AngularJS 需要后端服务器的 javascript 结果。
示例中的当前服务器返回angular.callbacks._0({"key": "value"});
javascript 标头。如何在 Rails 上以相同的格式返回?谢谢!
AngularJShttp://echo.jsontest.com/key/value?callback=angular.callbacks._0
默认从该请求生成链接
这是我的工作示例:
<!DOCTYPE html>
<html ng-app="Simple">
<body>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.min.js"></script>
<div ng-controller="SimpleController">
{{some_item.key}}
</div>
<script>
angular.module('Simple', ['ngResource']);
function SimpleController($scope, $resource) {
$scope.simple = $resource('http://echo.jsontest.com/key/value',
{callback:'JSON_CALLBACK'},
{get:{method:'JSONP'}}
);
$scope.some_item = $scope.simple.get();
console.log($scope.some_item.key);
}
</script>
</body>
</html>