【问题标题】:tornado server not returning response with self.write龙卷风服务器未使用 self.write 返回响应
【发布时间】:2010-07-30 00:25:14
【问题描述】:

我有一个像这样运行的简单龙卷风服务器:

import json
import suds
from suds.client import Client
import tornado.httpserver
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):

    def get(self):
        url = "http://xx.xxx.xx.xxx/Service.asmx?WSDL"
        client = Client(url)
        resultCount = client.service.MyMethod()
        self.write(json.dumps({'result_count':resultCount})) 

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    http_server = tornado.httpserver.HTTPServer(application)
    http_server.listen(6969)
    tornado.ioloop.IOLoop.instance().start()

现在,我有一个 jquery 函数,可以像这样调用这个龙卷风代码:

 $.get("http://localhost:6969",
            function(data){
                alert(data);
                $('#article-counter').empty().append(data).show();
            });

对于我的一生,我不明白为什么数据(响应)是空白的。甚至萤火虫也显示空白响应(尽管 http 状态为 200)。有人知道吗?

【问题讨论】:

    标签: jquery python tornado


    【解决方案1】:

    我终于弄清楚出了什么问题:我的应用没有遵循“同域来源”政策。因此,当发送 ajax 请求时,referrer 标头来自与我的龙卷风服务器不同的端口。服务器自然没有返回响应!

    【讨论】:

      猜你喜欢
      • 2013-11-03
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 2016-01-11
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      相关资源
      最近更新 更多