Marcos
Marcos

Reputation: 113

Why I can't send .load() Jquery with a form to the loaded page?

The next page loaded fine, without any error message, but does not show the posted data for {{nomeUsuario}} in jinja

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>

Upvotes: 0

Views: 29

Answers (1)

Paragon x3l0r
Paragon x3l0r

Reputation: 91

I think the reason is because you are not passing the posted value from the py file.

try this:

@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)

then 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>

Upvotes: 1

Related Questions