I'm making small web project based on Flask. And I have to send some data to Flask, but I don't know how to do it. I tried different ways, tried to use JSON, but I don't know how to work with it. Maybe someone can share working piece of code with me or help by explaining what I have to do?
new_freq = $('#input').val() //value I want to send
$.ajax({
url: '/set_freq',
type: 'POST',
data: ,
success: function(response){
$('#main').text(response)
}
})
Flask sends form data to template Flask to send form data to the template we have seen that http method can be specified in the URL rule. Form data received by the trigger function can be collected in the form of a dictionary object and forwarded to the template to render it on the corresponding web page.
We can also use Ajax to handle the user input rather than rendering a template. After carrying out the calculation client-side we will then pass the user input and results to the server to store in a database.
ajax() method allows you to send asynchronous http requests to submit or retrieve data from the server without reloading the whole page. $. ajax() can be used to send http GET, POST, PUT, DELETE etc.
new_freq = $('#input').val() //value I want to send
$.ajax({
url: '/set_freq',
type: 'POST',
data: new_freq,
success: function(response){
$('#main').text(response)
}
})
in Flask
new_freq = request.get_data()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With