如何解决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 举报,一经查实,本站将立刻删除。