天天看点

tornado ajax post,Ajax提交到Tornado后端Response是空白?

要实现的一个功能是post用户名密码,用Ajax得到一个status,然后确认是否传递成功,但是fire debug显示response是空白

这是handler,member是个类

pythonstatus_success = {

"status": True

}

status_fail = {

"status": False

}

class MainHandler(tornado.web.RequestHandler):

def post(self, *args, **kwargs):

username = self.get_argument("username")

password = self.get_argument("password")

email = self.get_argument("email")

new_member = {

"username": username,

"password": password,

"email": email

}

if Member.add_member(new_member):

print(status_success)

self.write(json_encode(status_success))

else:

self.write(json_encode(status_fail))

这是html单页

html

CLICK

这是javascript文件

javascript$(document).ready(function () {

$("#button").click(function () {

$.post("http://localhost:8000/", {

username: "xyz",

password: "xyz",

email: "xyz"

}, function (data) {

if(data.status == true){

alert("hello")

}

});

});

});

在控制台显示返回值空白,但是后端数据插入成功了。

tornado ajax post,Ajax提交到Tornado后端Response是空白?

但是使用命令行就会有返回值

tornado ajax post,Ajax提交到Tornado后端Response是空白?