web.py实现jsonp

浏览器端请求

$.getJSON("/currenttime?callback=?",
   function (json){
      $("#time").html(json);
   }
); 

服务器端响应

class currenttime:
   def GET(self):
   web.header('Content-Type', 'application/javascript;charset=utf-8')
   callback = web.input(callback='callback')['callback']
   import time, json
   p=time.strftime("%S")+"℃"
   return "%s(%s)" %(callback,json.dumps(p)) 
posted @ 2014-12-20 12:53  catmelo  阅读(471)  评论(0编辑  收藏  举报