2014-02-12 58 views
1

之前,我有这样的main.pySyntaxError:missing;声明

TODOS = { 
    'todo1': {'task': 'build an API'}, 
    'todo2': {'task': '?????'}, 
    'todo3': {'task': 'profit!'}, 
} 


class HelloWorld(restful.Resource): 
    def get(self): 
     return jsonify(TODOS) 

api.add_resource(HelloWorld, '/api') 

,并在客户端,我从angularjs使用:

var url = "/api?q=" + 'fdsf' + "&jsonp=JSON_CALLBACK"; 
$http.jsonp(url).success(function(data) { 
    console.log("get"); 
    this.busy = false; 
}.bind(this)); 

但是当我加载页面我有这个错误控制台:

SyntaxError: missing ; before statement 


"todo1": { 

我该如何解决这个错误?为什么jsonify函数不起作用?

编辑

铬:

Uncaught SyntaxError: Unexpected token : 

在Firefox:

SyntaxError: missing ; before statement 


"todo1": { 
+0

我认为问题可能是这行'todo3'结尾的额外逗号:{'task':'profit!'}, – doodeec

+0

@doodeec不,额外的','不会引发错误蟒蛇。 –

+0

@doodeec nope - 尾随分隔符在Python中很好... –

回答

5

您使用jsonp,但你的回应返回纯JSON。

JSONP(或具有填充 JSON)应包括回调函数,而不是一个普通的JSON响应。

您应该在这里使用$http.get()而不是$http.jsonp()

+1

它不适合我! –

+1

感谢您的回答 –