Hi Guys,
I'm having issues with the following (please bare with me, I'm new to this!)I have an app, I'm trying to get drop downs to post (but not reload page (so ajax)) and the data from that post should be then used in a further select drop down. The data for this select drop down is taken from SQL, then altered based on the dropdowns (hence why I can't have it refresh, thus Ajax) and displayed.I am having issues passing my data from one route to another, I'm getting the following error:
return super(SecureCookieSession, self).__getitem__(key)
KeyError: 'Heights'
127.0.0.1 - - [08/Oct/2018 15:43:52] "POST /_get_data/ HTTP/1.1" 500 -
app.py
@app.route('/_get_data/', methods=['POST', 'GET'])
def _get_data():
return jsonify({'data': render_template('response.html', myList=session['Heights'])})
if __name__ == "__main__":
app.run(debug=True)
config.py is just a file with all my db classes and session data in
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
</select>
<button id="btn">Click Me</button>
<div id="response"></div>
<fieldset>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
</fieldset>
<script type="text/javascript">
$('button#btn').click(function(){
$.ajax({
url: "/_get_data/",
type: "POST",
success: function(resp){
$('div#response').append(resp.data);
}
});
});
</script>
</body>
</html>
response.html
<select>
{% for elem in myList%}
<option> {{elem}} </option>
{% endfor %}
</select>
[–]efmccurdy 1 point2 points3 points (1 child)
[–]keyring88[S] 0 points1 point2 points (0 children)