提交表单时出现 MethodNotAllowedHttpException Stripe.js
MethodNotAllowedHttpException on Form Submission Stripe.js
我在试验 Stripe JS 时遇到了一些问题。以下是我的路线视图和 JS 文件。当我提交 post 时,出现以下错误,MethodNotAllowedHttpException
路线
> Route::get('buy', function () {
> return view('buy'); });
JS 文件
$( document ).ready(function(){
var StripeBilling = {
init: function(){
this.form = $('.billing-form');
this.submitButton = this.form.find('input[type=submit]');
var stripeKey = $('meta[name="secret-key"]').attr('content');
Stripe.setPublishableKey(stripeKey);
this.bindEvents();
},
bindEvents: function () {
this.form.on('submit', $.proxy(this.sendToken, this));
},
sendToken: function (event) {
this.submitButton.val('One Moment');
Stripe.createToken(this.form, $.proxy(this.stripeResponseHandler, this));
event.preventDefault();
},
stripeResponseHandler: function(status, response){
console.log(status, response);
}
};
StripeBilling.init();
})
默认视图
@section('content')
<div class="row">
<h1>Buy for </h1>
{!! Form::open(['id' => '#billing-form']) !!}
<div class="form-row">
<label>
<span>Card Number:</span>
<input type="text" data-stripe="number">
</label>
</div>
<div class="form-row">
<label>
<span>CVC:</span>
<input type="text" data-stripe="cvc">
</label>
</div>
<div class="form-row">
<label>
<span>Expiration:</span>
{!! Form::selectMonth(null , null, ['data-stripe' => 'exp-month']) !!}
{!! Form::selectYear(null, date('Y'),date('Y') + 10, null, ['data-stripe' => 'exp-year'] ) !!}
</label>
</div>
<div>
{!! Form::submit('submit') !!}
</div>
{!! Form::close() !!}
</div>
@stop
@section('footer')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://js.stripe.com/v2/"></script>
<script src="/js/billing.js"></script>
@stop
在您的路由文件中,您将路径定义为 GET 请求,但您的表单提交正在执行 POST 请求,要么更改您的表单以作为 GET 请求提交,要么更新您的路由,使其成为 POST 请求
我在试验 Stripe JS 时遇到了一些问题。以下是我的路线视图和 JS 文件。当我提交 post 时,出现以下错误,MethodNotAllowedHttpException
路线
> Route::get('buy', function () {
> return view('buy'); });
JS 文件
$( document ).ready(function(){ var StripeBilling = { init: function(){ this.form = $('.billing-form'); this.submitButton = this.form.find('input[type=submit]'); var stripeKey = $('meta[name="secret-key"]').attr('content'); Stripe.setPublishableKey(stripeKey); this.bindEvents(); }, bindEvents: function () { this.form.on('submit', $.proxy(this.sendToken, this)); }, sendToken: function (event) { this.submitButton.val('One Moment'); Stripe.createToken(this.form, $.proxy(this.stripeResponseHandler, this)); event.preventDefault(); }, stripeResponseHandler: function(status, response){ console.log(status, response); } }; StripeBilling.init(); })
默认视图
@section('content') <div class="row"> <h1>Buy for </h1> {!! Form::open(['id' => '#billing-form']) !!} <div class="form-row"> <label> <span>Card Number:</span> <input type="text" data-stripe="number"> </label> </div> <div class="form-row"> <label> <span>CVC:</span> <input type="text" data-stripe="cvc"> </label> </div> <div class="form-row"> <label> <span>Expiration:</span> {!! Form::selectMonth(null , null, ['data-stripe' => 'exp-month']) !!} {!! Form::selectYear(null, date('Y'),date('Y') + 10, null, ['data-stripe' => 'exp-year'] ) !!} </label> </div> <div> {!! Form::submit('submit') !!} </div> {!! Form::close() !!} </div> @stop @section('footer') <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script src="https://js.stripe.com/v2/"></script> <script src="/js/billing.js"></script> @stop
在您的路由文件中,您将路径定义为 GET 请求,但您的表单提交正在执行 POST 请求,要么更改您的表单以作为 GET 请求提交,要么更新您的路由,使其成为 POST 请求