Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  45] [ 7]  / answers: 1 / hits: 21343  / 11 Years ago, sun, august 25, 2013, 12:00:00

i'm trying to build a dynamic list on Flask.
Everyone who loads the page will see this list and can add or remove items from it. If something is added or removed, everybody receives this update.



I'm using Javascript to do some local processing on the list's items and Python to store it (in a singleton way) on the Flask server.



I want to have sure that there is consistency between items on python's list object and what javascript shows on the page, so i think the best option is make it read items from the python's list.



How can i make Javascript read items in this Python's list?


More From » python

 Answers
49

What you're looking for is AJAX. You can use this to query your server without reloading the page in the browser. When the page loads, you should grab a time object (using javascript) then every time someone commits their changes to Flask, record their time object along with the new contents. If the time object < the current, you'll need to compare the difference.



As far as reading items from a python list...you're going to need to figure out how you're returning the data from flask. If I were you, I would use the json module to encode your python data in json objects (similar to dictionaries) then return that to the calling browser; the reason is that json is a javascript native type.



You could also return a string and parse it on the client side.



Anyway, you can figure that out.



Flask and AJAX



JSON module



jQuery.ajax


[#76149] Friday, August 23, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bryonk

Total Points: 161
Total Questions: 116
Total Answers: 107

Location: Albania
Member since Sun, Nov 22, 2020
4 Years ago
bryonk questions
;