[英]I want to reload the page on button click and perform the route action in new tab
<form action="{{ route('payForEveryVoucherAndInvoice') }}" method="post" >
@csrf
<div class="row">
<div class="col-sm-4">
<div class="form-group">
<select id="payment_method" class="form-control" name="payment_method" required>
<option value="" selected="selected" disabled="disabled">Payment</option>
<option value="cash">Cash</option>
<option value="credit">Credit</option>
<option value="debit">Debit</option>
</select>
</div>
</div>
<div class="col-sm-1">
<input type="text" name="driver" value="{{$voucher_driver}}" hidden>
</div>
<div class="col-sm-5">
<button class="btn btn-primary" style="background-color: #262533; border-color: #262533" onClick="refreshPage()" formtarget="_blank">All Entries Paid</button>
</div>
</div>
</form>
This is my form.这是我的表格。 I am using onClick="refreshPage()" to refresh my page.
我正在使用 onClick="refreshPage()" 来刷新我的页面。
<script>
function refreshPage(){
window.location.reload();
}
</script>
This is the script.这是脚本。 But when i press the button.
但是当我按下按钮时。 It just reloads the page and also not going on the route.
它只是重新加载页面,也不在路由上。 I want to reload the page and open another tab to perform the route action.
我想重新加载页面并打开另一个选项卡来执行路由操作。
Any Help?任何帮助? Thanks in advance.
提前致谢。
You need to call submit event for that.您需要为此调用提交事件。
<script>
function refreshPage(){
$("form").submit();
window.location.reload();
}
</script>
I would recommend don't do this.我建议不要这样做。 use ajax as below.
使用ajax如下。
$('body').on('submit', 'form', function (e) {
e.preventDefault();
$.ajax({
url: $(this).attr('action'),
data: new FormData(this),
type: 'POST',
contentType: false,
cache: false,
processData: false,
success: function (data) {
window.location.reload();
},
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.