在此代码中,我使用的是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);

关于javascript - 在ajax成功后,window.location.href无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57111190/

10-09 21:08
查看更多