我使用stripe.js來學習自定義付款,我使用.net MVC創建一個簡單的網站來處理付款。我對webdev並不陌生,不能爲生我找出爲什麼這個js函數在提交按鈕點擊後沒有被調用,我現在把標記放入ViewBag中,這樣我就可以查看數據了。進一步的上下文中,我想處理令牌服務器端,同時生成令牌客戶端,我可能錯過了一些簡單的,但在這一點上,我已經嘗試了我能找到的所有東西
這是我用來測試卡充電的代碼 這是一個部分cshtml文件,在輸入數據時,這個cshtml將通過調用@Html.Partial("~/Views/Home/processors.cshtml")
@using System.Web.Mvc
@using System.Web.Mvc.Html
@using System
@using System.Web.UI
@model Dependency_Injection_MEF_MVC.Models.Payment
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
Stripe.setPublishableKey('pk_test_rob8TRTyyRseiTwrqSmheKiZ');
</script>
<script type="text/javascript">
$(function() {
var $form = $('#payment-form');
$form.submit(function (event) {
// Disable the submit button to prevent repeated clicks:
$form.find('.submit').prop('disabled', true);
// Request a token from Stripe:
Stripe.card.createToken($form, stripeResponseHandler);
// Prevent the form from being submitted:
return false;
});
});
function stripeResponseHandler(status, response) {
// Grab the form:
var $form = $('#payment-form');
if (response.error) { // Problem!
// Show the errors on the form:
$form.find('.payment-errors').text(response.error.message);
$form.find('.submit').prop('disabled', false); // Re-enable submission
} else { // Token was created!
// Get the token ID:
var token = response.id;
// Insert the token ID into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="Token">').val(token));
// Submit the form:
$form.get(0).submit();
}
};
</script>
<div class="row">
<div class="col-md-12 form-column">
<div class="form-container">
<form asp-controller="home" asp-action="InvoicePayment" method="POST" id="payment-form">
<span class="payment-errors"></span>
<div class="form-group">
<h3>Membership Amount: USD XX</h3>
</div>
<div class="form-group">
<label for="cardNumber">Card Number</label>
<input class="form-control form-input" id="cardNumber" type="text" size="20" data-stripe="number" style= "width:250px;height:25px;font-size:120%">
</div>
<div class="form-group">
<label>Expiration (MM/YY)</label>
<div>
<input class="form-control form-input date-input" type="text" size="2" data-stripe="exp_month" style= "width:250px;height:25px;font-size:120%">
<input class="form-control form-input date-input" type="text" size="2" data-stripe="exp_year" style= "width:250px;height:25px;font-size:120%">
</div>
</div>
<div class="form-group">
<label for="cvc">CVC</label>
<input class="form-control form-input" id="cvc" type="text" size="4" data-stripe="cvc" style= "width:250px;height:25px;font-size:120%">
</div>
<input class="submit" type="submit" id="submit" value="Submit Payment">
</form>
</div>
</div>
</div>
單擊提交時,瀏覽器開發人員控制檯中是否顯示任何錯誤? – justiceorjustus
nope它只是POSTS,然後重置頁面 –
我有這個部分視圖之外的另一個按鈕,也發佈基於'id = submit'會這是你認爲的衝突嗎?它不應該是正確的,因爲這只是關於'id =「payment-form」''var'form = $('#payment-form');' –