天天看點

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是空白?