I'm trying to poll the state of checkboxes (this is done in JS every three seconds). This solution returns "None" (see code below); Both printouts (with 'args' and with 'form') return "None". I'm expecting True/False, depending on the checkbox's boolean state.
index.html:
{% extends "layout.html" %} {% block content %} <div id="results" class="container">{{data_load|safe}}</div> <input id='testName' type='checkbox' value='Yes' name='testName'> {% endblock %} and the relevant flask app snippet:
@app.route('/', methods = ['GET', 'POST']) def index(): return render_template('index.html', data_load=timertry()) @app.route('/_timertry', methods = ['GET', 'POST']) def timertry(): print request.args.get('testName') print request.form.get('testName') return "some html going into 'results' div.." The JavaScript polling function (adapted from here):
$(document).ready(function() { $.ajaxSetup({cache : false}); setInterval(function() { $('#results').load('/_timertry?' + document.location ); }, 3000); // milliseconds! }); This should be simple enough, but none of the SO solutions I looked into (e.g., using jquery, adapting the flask/ajax example, etc.) worked.
EDIT: following mark's suggestion (including the javascript) and adding print request.values in index.html returns (seen on the console in Aptana):
CombinedMultiDict([ImmutableMultiDict([]), ImmutableMultiDict([])])
Clearly, the request seems empty. The post request is logged (when checkbox is pressed) as:
127.0.0.1 - - [03/Oct/2013 00:11:44] "POST /index HTTP/1.1" 200 -
Any ideas here?
request.form.get('testName'). Therequest.argsdict contains the values in the query string,request.formhas the form POST contents. Also,request.valueshas both combined./. Also, you say that it "doesn't work". What do you expect? I'm not sure whether you mean the code in your question returns None, or the code in the other answer returns None. Please edit your question and include these details.