1

请我尽可能在 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>""")

它确实显示了结果,但不在下拉列表中。 在此处输入图像描述

非常感谢

4

0 回答 0