javascript - (tornado)how can I pass argument to server when a button is pressed? -
i'm new python tornado.i'm building web site when want send argument server pressing button,i don't know how catch on tornado. how know button pressed ?
a simple ajax request jquery can job :
class application(tornado.web.application): """tornado web class. create routes used tornado_start""" def __init__(self): handlers = [ (r"/", index), (r"/explicit_action_url/", actionhandler) ] ... class actionhandler(tornado.web.requesthandler): def get(self): print("button click") class index(tornado.web.requesthandler): def get(self): self.render("index.html")
and in index.html
<button id="btn" type="button">click me</button> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script> $("#btn").click(function () { $.ajax({ type: 'get', url: "/explicit_action_url/", success: function (data) { alert("success") } }); }); </script>
Comments
Post a Comment