Denys
Denys

Reputation: 4557

Load new page on a button click (the button intentionally has no form)

There is a button on a page:

<input type="button"
         onclick="clickProcessOrder()"
         id="order-button"
         value="Order">

The function it triggers looks like this:

function clickProcessOrder() {
    $.get("/checkout");
}

The /checkout endpoint looks like this:

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

When I click a button, I can see that the get request successfully comes through:

127.0.0.1 - - [09/Aug/2019 17:17:05] "GET /checkout HTTP/1.1" 200 -

But I do not get redirected to checkout.html page. I stay on the same page.

What am I doing wrong? Is it possible to get redirected to checkout.html page through /checkout endpoint?

Upvotes: 0

Views: 37

Answers (1)

elkefreed
elkefreed

Reputation: 964

In your function you can do

window.location.href = "checkout.html";

Upvotes: 2

Related Questions