Laravel 如何在不重新加载页面的情况下在 Popup 中显示消息?我正在使用 CURL 发送数据
How to show message in Popup without reloading the page in Laravel? I am sending data using CURL
这是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 发送数据。我只想在提交表单后不刷新页面。我只想在弹出窗口中显示成功消息或错误消息。当我提交表单时,它会重新加载页面。我只是不想重新加载页面。
提前致谢。
尝试在页面加载时通过 Ajax 从控制器获取信息。成功响应使用 jquery.
替换内容
这是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 发送数据。我只想在提交表单后不刷新页面。我只想在弹出窗口中显示成功消息或错误消息。当我提交表单时,它会重新加载页面。我只是不想重新加载页面。
提前致谢。
尝试在页面加载时通过 Ajax 从控制器获取信息。成功响应使用 jquery.
替换内容