I have a button in my form.When user click it.It should send a request to the server to get a validate code.I am not sure how to realise it without refresh the page.Wait for your help,guys.Many thanks.
Asked
Active
Viewed 708 times
2 Answers
0
If you don't want to refresh the page, you should use Ajax as a request. Example using JQuery:
$.ajax({
type: "POST",
url: "~/pythoncode.py",
data: { param: text}
}).done(function( o ) {
// do something
});
Taken from this answer https://stackoverflow.com/a/13175665/2854344
0
Adding on to Joao's answer, after making the AJAX request using jQuery, you can access it like using the POST function:
class FrontPage:
def GET:
### Add some GET code here
def POST:
k = web.input()
user_input = k['param']
### Do something with user_input and sends back using AJAX

maverick97
- 132
- 2
- 8