【问题标题】:Why I can't send .load() Jquery with a form to the loaded page?为什么我不能将带有表单的 .load() Jquery 发送到加载的页面?
【发布时间】:2018-07-18 14:29:09
【问题描述】:

下一页加载正常,没有任何错误消息,但在jinja中没有显示{{nomeUsuario}}的发布数据

py:

@app.route('/Items', methods=['POST','GET'])
def Items():
    return render_template("Items.html")

Main.html:

<button type="submit" id="formbtn" name="nomeUsuario" value="{{ x[1] }}">Carregar</button>

<script>
    var nomeUsuario = $(this).val();
    $('#formbtn').on('click',function(){
        $("#menu").load('Items',nomeUsuario);
    }); 
</script> 

Items.html:

<h1>{{ nomeUsuario }}</h1>

【问题讨论】:

  • this 是所示上下文中的window。它没有val()。还需要一个键/值对发送到服务器
  • 你可以给我一个关于如何使用 .load() 发送这个键/值的例子吗?

标签: jquery html post flask load


【解决方案1】:

我认为原因是您没有从py 文件传递​​发布的值。

试试这个:

@app.route('/Items', methods=['POST','GET']) def Items(): item = request.form["value_posted_here"] if "value_posted_here" in request.form else "" return render_template("Items.html", nomeUsuario = item)

然后是html:

<button type="submit" id="formbtn" name="nomeUsuario" value="{{ x[1] }}">Carregar</button>

<script>
    var nomeUsuario = $(this).val();
    $('#formbtn').on('click',function(){
        $("#menu").load('/Items',{'value_posted_here': nomeUsuario });
    }); 
</script>

【讨论】:

    猜你喜欢
    • 2017-06-22
    • 2011-01-13
    • 1970-01-01
    • 2020-10-28
    • 2020-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多