admin管理员组文章数量:1316974
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?
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?
Share Improve this question asked Aug 25, 2013 at 1:20 Pedro AlvesPedro Alves 1,7284 gold badges18 silver badges37 bronze badges1 Answer
Reset to default 3What 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 mits their changes to Flask, record their time object along with the new contents. If the time object < the current, you'll need to pare 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
本文标签: How to make javascript work with python on FlaskStack Overflow
版权声明:本文标题:How to make javascript work with python on Flask? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742020194a2414471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论