使用JavaScript从Laravel上传数据

我有这个问题,在使用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>
xuchong891101 回答:使用JavaScript从Laravel上传数据

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3160947.html

大家都在问