问题很明显,我发布了strip元素表单,我将其发布为POST
请求,结果是null
,我正在获取请求输出及其{{1} }。
Js代码:
null
HTML代码形式:
var form = document.getElementById('payment-form');
$("#submitNewCard").click(function(event) {
event.preventDefault();
stripe.createToken(card).then(function(result) {
if (result.error) {
let errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
let stripToken = result.token;
let formData = new FormData(form);
formData.append('stripe_key', JSON.stringify(stripToken));
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url: "/add/new/card",
type: "post",
data: formData,
cache: false,
contentType: false,
processData: false,
beforeSend: function() {
$('#cover').show();
},
success: function(response) {
$('#cover').hide();
return true;
},
error: function(error) {
$('#cover').hide();
toastr.error(error.responseJSON.message);
}
});
}
});
});
我想念什么?为什么<form method="post" id="payment-form">
{{csrf_field()}}
<input type="hidden" name="HelloHidden" value="hidden value">
<div class="form-row">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">
</div>
<div id="card-errors" role="alert"></div>
</div><br/>
<button type="button" id="submitNewCard" class="btn btn-primary">Add Card</button>
</form>
为空。