我試圖在沒有頁(yè)面刷新或重定向的情況下提交表單請(qǐng)求并存儲(chǔ)數(shù)據(jù)。并將成功消息發(fā)送到 @if (session('message')) <div class="alert alert-success"> {{ session('message') }} </div> @endif,單擊提交按鈕后我得到白頁(yè)并有以下響應(yīng){"msg": "Setting created successfully"}html 表單:<form method="POST" action="/mail/store" id="contactForm"> @csrf <div style="display: flex;" class="name-email"> <div class="form-group col-sm-6 fl_wrap"> <input type="text" name="name" value="{{ old('name') }}" id="name" class="form-control fl_input" placeholder="Name" required> </div> <div class="form-group col-sm-6 fl_wrap"> <input type="text" name="email" value="{{ old('email') }}" id="email" placeholder="Email" class="form-control fl_input" required> </div> </div> <div class="form-group col-sm-12 fl_wrap mt-2"> <textarea type="text" name="message" rows="7" value="{{ old('message') }}" id="message" class="form-control fl_input" placeholder="message" required></textarea> </div> <div class="form-group text-center mt-5"> <button type="submit" value="save" id="submit" class="btn btn-warning submit" style="color: white;background: rgb(59, 199, 246); border-color: rgb(59, 199, 246); width: 140px;"> send </button> </div></form>Js 代碼:我認(rèn)為 ajax 代碼有問(wèn)題或缺失,但我不知道在哪里 <script src="/js/jquery.min.js"></script> <script !src="" type="text/javascript"> $(document).ready(function () { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } });
如何在不刷新頁(yè)面的情況下使用ajax提交表單請(qǐng)求并在laravel中返回消息?
三國(guó)紛爭(zhēng)
2022-12-11 09:58:12