未捕获的SyntaxError:意外的令牌:在AngularJS中

前端之家收集整理的这篇文章主要介绍了未捕获的SyntaxError:意外的令牌:在AngularJS中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经在这个工作了几个小时,似乎无法到达任何地方.我希望这是发布此内容的正确位置.我是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>

以下是我的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(); 
}

当我运行它(在chrome中)时,我得到:

未捕获的SyntaxError:意外的令牌:

json回归看起来很棒所以我不明白为什么这是一个问题.

谢谢

解决方法

因为您使用的API返回JSON而不是 JSONP.JSONP的有效负载应该包含一个函数,如functionCall({“Name”:“Foo”,“Id”:1234,“Rank”:7});

猜你在找的Angularjs相关文章