[英]window.location.href not working after ajax success
在這段代碼中,我使用的是razorpay
付款網關api,其中付款已成功完成,但在成功執行ajax調用后無法重定向。 那么,如何在訂單頁面中使用window.location.href
重定向頁面? 請幫我。
$(document).ready(function() {
$('#buy_now').click(function(e) {
var total_amount = $(".total_amount").val();
var product_id = $(".product_id").map(function() {
return this.id;
}).get().join(",");
var new_uid = $("#new_uid").val();
var user_id = $("#uid").val();
var user_email = $(".user_email").attr("id");
var options = {
"key": "************************",
"amount": (1 * 100), // 2000 paise = INR 20
"name": "MyApp",
"description": "Payment",
"image": "https://www.MyApp.com/img/logo/logo.png",
"handler": function(response) {
$.ajax({
url: '<?php echo base_url() ?>razorPaySuccess',
type: 'post',
dataType: 'json',
data: {
"razorpay_payment_id": response.razorpay_payment_id,
"total_amount": total_amount,
"product_id": product_id,
"new_uid": new_uid,
"user_email": user_email,
"user_id": user_id
},
success: function(data) {
window.location.href = "<?php echo base_url(); ?>order";
}
});
},
"theme": {
"color": "#528FF0"
}
};
var rzp1 = new Razorpay(options);
rzp1.open();
e.preventDefault();
});
});
將您的網址存儲在變量中,然后調用此行。
var url = "your current url";
$(location).attr('href',url);
到目前為止,我還沒有注意到您的代碼有任何錯誤..您只需確保它能夠success: function()
並使用window.location.replace
而不是window.location.href
。 因此它將替換當前的URL並將您重定向到成功頁面。
window.location.replace = "<?php echo base_url(); ?>order";
如果上面的代碼仍然不起作用。 您的e.preventDefault()
可能會導致您無法重定向到成功頁面,因此請確保相應地使用它。
這樣做:
var path = "<?php echo base_url(); ?>";
window.location.href = path+"order";
window.location.href = window.location.href; it may work for you.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.