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 »</button>
How can I redirect it to this url -- {% url 'book:booking' %}
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
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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.