JavaScript 干扰 ASP.NET MVC 控制器操作

问题描述

我正在尝试将 this Braintree code 集成到我们的 ASP.NET MVC 网站中。当我在 JavaScript 函数的末尾添加ajax 调用时...

$.ajax({
        type: "POST",url: '/store/payment/',data: { id: nonce }
    });

...调用了正确的控制器操作,但我从未到达我请求的 Confirm 视图(我什至可以在 Confirm 视图代码上使用 Visual Studio 调试器移动)。出于某种原因,我总是在浏览器中看到原始付款页面。为什么?是否有任何 JavaScript 隐藏行为会重新加载原始页面

    [HttpPost]
    [Authorize(Roles = "customer,admin")]
    public ActionResult Payment(Paymentviewmodel payment,string id)
    {
       if (id != null)
       {
           payment.Nonce = id;

           Session.Add("payment",payment);

           return RedirectToAction("Confirm");
       }
        
       return View(payment);
   }

来自 this example 的 JavaScript:

function showNonce(payload,liabilityShift) {
    nonceSpan.textContent = "Liability shifted: " + liabilityShift;
    nonceInput.value = payload.nonce;
    payGroup.classList.add('hidden');
    payGroup.style.display = 'none';
    nonceGroup.classList.remove('hidden');
}

payBtn.addEventListener('click',function (event) {
    payBtn.setAttribute('disabled','disabled');
    payBtn.value = 'Processing...';

    var billingIsValid = validateBillingFields();

    if (!billingIsValid) {
        enablePayNow();

        return;
    }

    dropin.requestPaymentMethod({
        threeDSecure: {
            amount: '100.00',email: billingFields.email.input.value,billingAddress: {
                givenname: billingFields['billing-given-name'].input.value,surname: billingFields['billing-surname'].input.value,phoneNumber: billingFields['billing-phone'].input.value.replace(/[\(\)\s\-]/g,''),// remove (),spaces,and - from phone number
                streetAddress: billingFields['billing-street-address'].input.value,extendedAddress: billingFields['billing-extended-address'].input.value,locality: billingFields['billing-locality'].input.value,region: billingFields['billing-region'].input.value,postalCode: billingFields['billing-postal-code'].input.value,countryCodeAlpha2: billingFields['billing-country-code'].input.value
            }
        }
    },function (err,payload) {
        if (err) {
            console.log('tokenization error:');
            console.log(err);
            dropin.clearSelectedPaymentMethod();
            enablePayNow();

            return;
        }

        if (!payload.liabilityShifted) {
            console.log('Liability did not shift',payload);
            showNonce(payload,false);
            
            return;
        }

        console.log('verification success:',payload);
        showNonce(payload,true);

        // send nonce and verification data to your server

        var nonce = payload.nonce;

        $.ajax({
            type: "POST",data: { id: nonce }
        });
    });
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)