这是dashboard.blade.php
我的观点。
<form class="form-horizontal" role="form" method="post" action="{{url('/dashboard/validate')}}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-md-6">
<fieldset style="height: auto;">
<legend>Complaint Details</legend>
<div class="form-group row">
<label class="col-md-6 control-label" for="pnr">PNR/Unreserved Tickets No <span class="errors">*</span>: </label>
<div class="col-md-6">
<input type="text" class="form-control" maxlength="10" name="pnr" id="pnr" placeholder="PNR/Unreserved Tickets No." required>
</div>
</div>
</div>
</div>
</form>
这是我的DashboardController.php
public function formSubmit(Request $request){
$data1 = [
'name'=> $passName,
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "xyz.com",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS =>$data1,
CURLOPT_HTTPHEADER => array(
"Content-Type: multipart/form-data",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return redirect()->back()->with('message', 'Error on submitting form.');
} else {
return redirect()->back()->with('message', 'Thank You for Submitting Complaint');
}
}
工作正常。我通过Laravel中的CURL发送数据。我只是想在提交表格后不刷新页面。我只想在弹出窗口中显示Successful消息或错误消息。当我提交表单时,它会重新加载页面。我只是不想重新加载页面。
提前致谢。
答案 0 :(得分:2)
尝试在页面加载时通过Ajax从控制器获取信息。成功响应使用jquery替换内容。