请我尽可能在 python 中处理前端,并通过 ajax 使其动态化:
这是客户端:
<div id="gene">
<!-- <select id="gene"> -->
<!-- add an empty value -->
<!--<option value="*">-- Select --</option> -->
<!--</select>-->
</div>
和 Ajax 函数在同一个文件中:
var updateGeneInput = function(){
$.ajax({
url: 'get.py',
type: 'get',
data: {'table':'gene'},
success: function(data){
$("#gene").html(data);
}
});
};
我想检索选项以使用 cgi (get.py) 填充下拉列表:
if (table == "gene"):
query = """
SELECT category
FROM Categories
"""
cursor.execute(query)
rows=cursor.fetchall()
print("""<select >""")
print("""<option value='*'>- Select -</option>""")
for row in rows:
print("""<option value="s%">s%</option>"""%row)
print("""</select>""")
非常感谢
