Twisted.Web和AJAX [英] Twisted.Web and AJAX

查看:158
本文介绍了Twisted.Web和AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Twisted.Web实施的玩具Web服务:

I've implemented a toy web service in Twisted.Web:

from twisted.web import server, resource, http

class RootResource(resource.Resource):
    def __init__(self):
        resource.Resource.__init__(self)
        self.putChild('test', TestHandler())

class TestHandler(resource.Resource):
    isLeaf = True

    def __init__(self):
        resource.Resource.__init__(self)
    def render_GET(self, request):
        return self.render_POST(request)
    def render_POST(self, request):
        return "hello world!"

if __name__ == "__main__":
    import sys
    from twisted.internet import reactor
    reactor.listenTCP(8082, server.Site(RootResource()))
    reactor.run()

据卷曲它工作正常:

According to curl it works fine:

$ curl --url http://localhost:8082/test -v
[..]
< HTTP/1.1 200 OK
< Date: Mon, 02 Aug 2010 11:54:35 GMT
< Content-Length: 13
< Content-Type: text/html
< Server: TwistedWeb/8.2.0
< 
hello world!

现在,我想打电话给使用的jQuery提供的AJAX方法的服务。 下面是相应的Java脚本code:

Now, I'd like to call the service using the AJAX methods provided by JQuery. Here is the corresponding Java Script code:

[..]
// Submit button
$("#submit").click(function(e){
    $.ajax({type: "POST", 
            url: "http://localhost:8082/test",
            data: {},
            success: function(data) {
              alert("Success:" + data);                  
            }
    });
});
[..]

虽然成功回调被调用,数据等于。没有任何人有一个线索,为什么?

Although the success callback gets called, data equals null. Does anybody have a clue why?

谢谢,  彼得·

推荐答案

我无法重现该问题。我已经使用你的服务器,并使用jQuery您的具体Ajax调用和它加载的罚款。该警告框显示成功:世界,你好!如预期。你必须有别的东西是错误的。

I can't reproduce the issue. I have used your server and your exact ajax call with JQuery and it loads fine. The alert box shows "Success: hello world!" as expected. You must have something else wrong.

这篇关于Twisted.Web和AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆