![](/img/trans.png)
[英]How to submit a form request using ajax without page refresh and return a message in laravel?
[英]Laravel Submit Form Without Page Refresh Using Ajax
我想在我的模態彈出表單中發布電話號碼。但不想在點擊“繼續”按鈕提交表單后消失彈出窗口。 這是我的刀片。php 代碼。
<div id="modal-wrapper" class="modal">
<form class="modal-content animate" id="addform">
<input type="text" class="form-control" name="phone_number" placeholder="01**********">
</div>
</div>
<div style="text-align: center; margin-top: 10px;padding-left:18px;">
<button type="submit" style="background-color: #a5abb0;" class="mobile-login__button">CONTINUE
</button>
</div>
這是我的 ajax 部分代碼的腳本部分。
<script>
$("#addform").on('submit',function(e){
e.preventDefault();
$.ajax({
type:"post"
url: "/client-mobile-login"
data: $("addform").serialize(),
success:function(response){
},
error:function(error){
console.log(error)
alert("not send");
}
)};
});
});
</script>
這是我的 controller function
public function client_mobile_login(Request $request)
{
$client_phone1='88'.$request->input('phone_number');
$result=DB::table('client')
->where('client_phone1',$client_phone1)
->first();
{{ here is my otp sending code.... }}
if($result)
{
$request->session()->put('client_title', $result->client_title);
// print_r($client_phone1);
}
使用類型=按鈕
<button type="button" id="submitForm" ...>CONTINUE</button>
並在點擊事件上觸發您的 ajax
$("#submitForm").on('click',function(e){ ... }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.