2 8*_*2 8 1 python flask angularjs
我有这个main.py:
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')
Run Code Online (Sandbox Code Playgroud)
在客户端我使用angularjs:
var url = "/api?q=" + 'fdsf' + "&jsonp=JSON_CALLBACK";
$http.jsonp(url).success(function(data) {
console.log("get");
this.busy = false;
}.bind(this));
Run Code Online (Sandbox Code Playgroud)
但是当我加载页面时我在控制台中有这个错误:
SyntaxError: missing ; before statement
"todo1": {
Run Code Online (Sandbox Code Playgroud)
我怎么能解决这个错误?为什么jsonify功能不起作用?
编辑
在铬:
Uncaught SyntaxError: Unexpected token :
Run Code Online (Sandbox Code Playgroud)
在Firefox中:
SyntaxError: missing ; before statement
"todo1": {
Run Code Online (Sandbox Code Playgroud)
您正在使用jsonp,但您的响应返回纯JSON.
JSONP(或带有填充的JSON)应包含回调函数,而不是普通的JSON响应.
你应该$http.get()在这里使用,而不是 $http.jsonp().
| 归档时间: |
|
| 查看次数: |
2303 次 |
| 最近记录: |