임지웅
임지웅

Reputation: 151

Data from javascript to python(using post)

I am trying to give data from javascript to python, using post

On my Javascript

$('ABC').on("click", function(){
    $.post( '/user',
        {
            user: 'here'
        }
    )});

And giving this to python

@app.route("/user", methods=['GET', 'POST'])
def user():
    id = user
    return id

Above code should show html with just user.

But page does not move when on click..

Any idea?

Upvotes: 1

Views: 93

Answers (1)

Barmar
Barmar

Reputation: 782407

You need to provide a callback function in $.post

$('ABC').on("click", function() {
  $.post('/user', {
    user: 'here'
  }, function(response) {
    $("#result").html(response);
  });
});

You can also abbreviate this to the .load() method:

$('ABC').on("click", function() {
  $("#result").load('/user', {
    user: 'here'
  });
});

Upvotes: 1

Related Questions