我已经在这个工作了几个小时,似乎无法到达任何地方.我希望这是发布此内容的正确位置.我是StackOverflow的新手,所以如果这不正确,请引导我到正确的地方.
我有以下html文件:
<!DOCTYPE HTML>
<html ng-app="DishClips">
<head>
<script type="text/javascript" src="http://code.angularjs.org/angular-1.0.0.0rc4.min.js"></script>
<script type="text/javascript" src="http://code.angularjs.org/angular-resource-1.0.0.0rc4.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/css/bootstrap.min.css">
<script type="text/javascript" src="./dishclips.js"></script>
</head>
<body>
<div ng-controller="DishClipsCtrl">
<table class="table table-striped">
<tr ng-repeat="restaurant in dishclipsResult.results"></tr>
<td>{{restaurant.name}}</td>
</table>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
以下是我的dishclips.js:
angular.module('DishClips', ['ngResource']);
function DishClipsCtrl($scope, $resource) {
$scope.dishclips = $resource('http://apiv2.dishclips.com/dishclips/api/:action',
{action:'searchRestaurants',address:'irvine',callback:'JSON_CALLBACK' },
{get:{method:'JSONP'}});
$scope.dishclipsResult = $scope.dishclips.get();
}
Run Code Online (Sandbox Code Playgroud)
当我运行它(在chrome中)时,我得到:
未捕获的SyntaxError:意外的令牌:
json回归看起来很棒所以我不明白为什么这是一个问题.
谢谢
因为您使用的 API 返回JSON而不是JSONP。的JSONP有效负载应该用这样的函数包装functionCall({"Name": "Foo", "Id": 1234, "Rank": 7});
| 归档时间: |
|
| 查看次数: |
30722 次 |
| 最近记录: |