ScriptTagProxy 当向服务器请求时,会自动带一个callback参数,如下:
http://xxxxxx/get_json?_dc=1285827704378&callback=stcCallback100
同时要求服务器回写 json数据时前面要包含这个 callback 参数的值,结构如下:
stcCallback100({"totalCount": "1234", "topics": [{"forumid": "7", "author": "author",
"lastpost": "1285803622", "threadid": "1112", "title": "title", "excerpt": "aaaa", "forumtitle": "ext", "lastposter": "xulong"}]})
下面是 服务器使用 django 的代码:
def contract_json(request):
callback=request.GET.get("callback")
jsonData={"totalCount":"1234","topics":
[{"threadid":"1112","forumid":"7","forumtitle":"ext",
"title":"title","author":"author","lastposter":"xulong",
"lastpost":"1285803622","excerpt":"aaaa"}]
}
res = HttpResponse()
res.write(callback)
res.write('(')
res.write(json.dumps(jsonData))
res.write(')')
return res