I have a web form that sends a request to send ajax to a tornado server containing the form data, but the answer
self.write(message)
just displayed in browser instead of js processing it. How can i fix this?
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); }
source share