0

I have created a post request in jquery. It sends an XHR request and it gets completed successfully. However, I also want to redirect it to a different page when that request is triggered.

this is my code:

$(".checkout-button").click(function(){
    $.post("{% url 'book:booking' %}", seat_total, function(response){});
           });

this is my button to which this is linked

<button class="checkout-button">Checkout &raquo;</button>

How can I redirect it to this url -- {% url 'book:booking' %}

DontVoteMeDown
  • 21,122
  • 10
  • 69
  • 105
K. Grewal
  • 51
  • 1
  • 12

2 Answers2

1

the callback doesn't do anything fancy to the code within it just changes when that code is executed.

Just add this line:

window.location.href = http://www.google.com;

and replace google with your link

Ben
  • 609
  • 11
  • 19
1

Specific solution to your question:

$(".checkout-button").click(function(){
    $.post(
        "{% url 'book:booking' %}", 
        seat_total, 
        function (response) {
            window.location.href = "{% url 'book:booking' %}"
        }
    );
});

General answers how to redirect with JavaScript: How to redirect to another webpage in JavaScript/jQuery?

Community
  • 1
  • 1
Daniel Diekmeier
  • 3,401
  • 18
  • 33