What is the handler of your MainHandler or WSHandler function,
Only one of them is called at a time, so your syntax event = MainHandler.event will not give you the result.
- If your goal is only to submit the form. Then, when sending an event type, you need to write a message or get a function related to your send call in your JS. This will work with the normal server-side tornado.web.RequestHandler.
Ref. tornado chat example
I updated the chat example:
$(document).ready(function() { if (!window.console) window.console = {}; if (!window.console.log) window.console.log = function() {}; $("#messageform").live("submit", function() { newMessage($(this)); return false; }); $("#message").select(); } }); function newMessage(form) { var message = form.formToDict(); var disabled = form.find("input[type=submit]"); disabled.disable(); $.postJSON("URL", message, function(response) { console.log(response); }); } function getCookie(name) { var r = document.cookie.match("\\b" + name + "=([^;]*)\\b"); return r ? r[1] : undefined; } jQuery.postJSON = function(url, args, callback) { args._xsrf = getCookie("_xsrf"); $.ajax({url: url, data: $.param(args), dataType: "text", type: "POST", success: function(response) { if (callback) callback(eval("(" + response + ")")); }, error: function(response) { console.log("ERROR:", response) }}); };
When you call $("#message").submit() , you will receive the form data in your URL function
If you want to use WSHandler then
Ref. example will help you.
See if that helps.
source share