我有这个问题,在使用laravel控制器将数据添加到数据库之前,必须使用javascript进行一些验证。但是,如果没有错误,则应继续向数据库中添加数据 这是我的javascript
function receiptCheck() {
var x = new Boolean(false);
//some code
if (x==false) {
var x = new FormData($('#formReceipt')[0]);
//Add data to database
$.post('{{ route("receiptFinish") }}',{x,_token:'{{ csrf_token() }}'},function(data){
// console.log(data);
});
}
else {
if (window.confirm("QTY not matched,proceed anyway?")) {
alert('you pressed ok');
}
}
}
我的web.php
Route::get('/goods/receiptFinish','AjaxController@receiptFinish')->name('receiptFinish');
我的控制器
function receiptFinish(Request $request)
{
while ($i=0 <= $total) {
echo $request->receipt.$i;
$i++;
}
}
我的html
<form id="formReceipt">
<input type="text" name="receipt1">
<input type="text" name="receipt2">
</form>