执行AJAX调用时Jquery / Browser挂起

时间:2012-03-31 04:22:46

标签: jquery ajax

我有一个电子商务网站,通过支付网关接收信用卡付款。客户输入他们的信用卡详细信息并按提交,系统使用Jquery对网关进行API调用,并且响应成功或失败。这通常有效,但每10次(随机)中有1次似乎只是悬挂。现在我不确定是不是因为API没有返回某些内容或者Jquery ajax调用正在播放...有没有办法找到答案?

我使用的网关提供商非常有信誉,我非常怀疑它们的API存在问题。所以我认为它与我的代码有关。有人可以通过建议我如何确定问题并进行调试来帮助我。

感谢提前!! :)

这是代码,它包含在validate插件中......

$("#form_checkout").validate({
    focusCleanup: false,
    focusInvalid: true,
    onkeyup: false,
    invalidHandler: function(form, validator) {

        var errors = validator.numberOfInvalids();
        if (errors) {
            alert("Looks like you have missed or made mistakes on "+errors+" fields");
        }

    },
    submitHandler: function(form) {

        // disable the place order button to stop customer from pressing it twice
        $("#button_place_order").fadeOut('fast',function() {
            $("#button_place_order_disabled").fadeIn('fast');
        });

        var aCheckoutForm = $("#form_checkout").serializeArray();

        // #nOrderId will only exist if user firstly submits, then navigates away from checkout and comes back
            $.post('/core/ajax/cart.ajax.php', { pAction: "checkout",
                                                     pOrderId: $("#nOrderId").val(),  
                                                     pCheckoutForm: aCheckoutForm }, 
                                                     function(data) {
            if (data != null && data.sSessionExists != 'N') {

                $("#nOrderId").val(data.nOrderId);

                // if payment is successful then go to receipt page
                if (data.TxnResult == 'true') {

                    if ($("#sPaymentType").val() == 'form_payment_paypal') {
                        window.location.replace('/front/paypal-link.php');
                    }
                    else {
                        alert ('Thank you, click OK to continue');                              
                        window.location.replace("/front/receipt.php?pOrderNumber="+data.sOrderNumber);
                    };

                }
                else {
                    // only allow 4 attempts at cc payment
                    maxCcTries = maxCcTries+1;
                    if (maxCcTries >= 4) {
                        alert ('All of your details have been recorded but the transactions were not successful, please contact us to complete your order');
                        window.location.replace("/logout.php");                 
                    }
                    else {
                        alert ('The credit card payment has failed, please check your details and try again.');
                        // re-enable the place order button if credit card details failed so customer can try again                     
                        $("#button_place_order_disabled").fadeOut('fast',function() {
                            $("#button_place_order").fadeIn('fast');
                        });
                    };
                }; // end txn result
            }
            else {
                // timeout
                alert ('Due to extended inactivity, your session has timed out. Please add products to your cart again');
                window.location.reload();
            }; // end session check

        }, "json"); // end post

        return false;
    }
}); // end form_checkout

1 个答案:

答案 0 :(得分:0)

我最近遇到了这类问题 我发现了两个问题, 1.首先,您的请求/响应在第三方插件发送时处理得更多,并且任何防病毒软件都会尝试检查您的请求。(这是客户端问题)。

  1. 现在我的网关在我的网关安装了一个防火墙的问题,它每次检查请求/响应。
  2. 所以我的反应很慢,我希望这会对你有帮助。