我有一个网页表单,它向包含表单数据的龙卷风服务器发送ajax post请求,但是
的响应self.write(message)
只是在浏览器中显示而不是js处理它。我怎么能纠正这个?
class NewHandler(BaseHandler):
@tornado.web.authenticated
def post(self):
message = {
"id": str(uuid.uuid4()),
"from": self.current_user["name"],
"body": self.get_argument("body"),
}
message["html"] = tornado.escape.to_basestring(self.render_string("message.html", message=message))
self.write(message)
messages.new([message])
js code:
$(document).ready(function() {
document.session = $('#session').val();
$('#messageform').submit(function(event) {
var formdata = $('#messageform').formData();
var button = $('#messageform').find("input[type=submit]");
button.prop("disabled", true);
jQuery.ajax({
url: '/new',
type: 'POST',
data: formdata,
success: function(response){
messageBox.show(eval("("+response+")");
button.prop("disabled", false);
}
});
};
var messageBox = {
show: function(message){
var content = $(message.html);
$("#inbox").append(content);
}
答案 0 :(得分:0)
尝试在self.write()方法之后提升StopIteration:
self.write(somedata)
raise StopIteration