laravel-blade 相关问题

Blade是Laravel提供的简单而强大的模板引擎。与其他流行的PHP模板引擎不同,Blade不会限制您在视图中使用纯PHP代码。

分页显示大箭头/无法正常工作?

我使用简单的 Laravel 分页命令 {{$blogs->links()}} 来发布博客文章,但显示错误。经过研究,我将 Bootstrap 的一个版本作为“链接”方法的论据,

回答 1 投票 0

Laravel 分页显示大箭头/无法正常工作?

我使用简单的 Laravel 分页命令 {{$blogs->links()}} 来发布博客文章,但显示错误。经过研究,我将 Bootstrap 的一个版本作为“链接”方法的参数,

回答 1 投票 0

LARAVEL:如何显示引导模式中的数据?

我在显示模态数据时遇到问题。它在模态之外工作,但在模态内部它只迭代 1 个数据。 @foreach ($addresses->sortByDesc('status') as $address) ...

回答 1 投票 0

Laravel 组件在一个文件中被识别,但在另一个文件中无法识别

我已经解决了这个问题,但是我对这里发生的事情非常困惑,希望有人向我解释一下以供将来参考。 所以我有一个 Laravel 10 项目,我的第一条路线是

回答 1 投票 0

无法将变量传递给 Laravel x 组件

我正在 Laravel 8 中的某些地方使用 x 组件构建一个网页。组件是存在于所有页面中的模式,但其内容必须根据调用它的页面而改变。 我的想法是

回答 3 投票 0

laravel Blade 包含具有相对路径的文件

在 Laravel Blade 系统中,当我们想要包含部分 Blade 文件时,我们必须每次都为每个文件写入完整路径。当我们重命名文件夹时,我们必须检查

回答 4 投票 0

无法在laravel中使用Livewire和blade检索数据

我正在为用户创建一个提交案例的功能,我可以将案例保存到数据库,但我无法从数据库中检索它。这是代码。 1.manage-case.php组件 我正在为用户创建一个提交案例的功能,我可以将案例保存到数据库,但我无法从数据库中检索它。这是代码。 1.manage-case.php组件 <?php namespace App\Http\Livewire; use App\Models\Cases; use Livewire\Component; class ManageCase extends Component { public $cases; public $title; public $description; public $status; public $feedback; public function render() { // Load the Livewire view with the current user's cases return view('livewire.manage-case'); } public function addCase() { $cases = new Cases(); $cases->title = $this->title; $cases->description = $this->description; $cases->status = 'pending'; $cases->feedback = 'pending for admin reply'; $cases->id = auth()->user()->id; $cases->save(); $this->resetFields(); return redirect()->route('manage-case'); } public function getUserCases() { // Retrieve cases belonging to the authenticated user $this->cases = Cases::where('id', auth()->user()->id)->get(); } private function resetFields() { // Reset input fields to their default values $this->title = ''; $this->description = ''; $this->status = ''; $this->feedback = ''; } } 2.管理案例.刀片 <div class="flex"> <div class="w-1/5"> <ul class="list-none text-xl flex flex-col items-center rounded-lg bg-gray-200 p-4"> <li class="mt-6 mb-6"><a href="" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Orders</a></li> <li class="mt-6 mb-6"><a href="{{route('manage-location')}}" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Addresses</a></li> <li class="mt-6 mb-6"><a href="#" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Insurance</a></li> <li class="mt-6 mb-6"><a href="#" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Review</a></li> <li class="mt-6 mb-6"><a href="{{route('manage-case')}}" class="block hover:bg-gray-300 transition-colors duration-200 p-2 rounded-lg">Cases</a></li> </ul> </div> <div class="w-4/5"> <div> <label for="title" class="input-label w-32">Title</label><br> <input type="text" wire:model="title" class="input-field"> </div> <div> <label for="description" class="input-label w-32">Description</label><br> <input type="text" wire:model='description' class="input-field rounded-sm"> </div> <div> <button class="" wire:click='addCase'>Submit</button> </div> </div> <div class="mt-10"> <div class="flex flex-wrap"> @if ($cases !== null && count($cases) > 0) @foreach ($cases as $case) <div class="w-full md:w-1/2 lg:w-1/3 px-2 mb-4"> @livewire('retrieve-case', ['caseid' => $case->caseID], key($case->caseID)) </div> @endforeach @else <p>no record found</p> @endif </div> </div> </div> 3.retrieve-case.php组件 <?php namespace App\Http\Livewire; use Livewire\Component; use App\Models\Cases; class RetrieveCase extends Component { public $cases; public $caseID; public $title; public $description; public $status; public $id; public function mount($caseID){ $this->cases = Cases::find($caseID); $this->caseID = $caseID; $this->title = $this->case->title; $this->description = $this->case->description; $this->status = $this->case->status; $this->id = $this->case->id; } public function render() { return view('livewire.retrieve-case'); } public function deleteCase(){ $this->cases->delete(); $this->emit('caseDeleted'); } public function getUserCases() { // Retrieve cases belonging to the authenticated user $this->cases = Cases::where('id', auth()->user()->id)->get(); } } 4.retrieve-case.blade <!-- resources/views/livewire/retrieve-case.blade.php --> <div> <h2>Case Details</h2> @if ($case) <ul> <li> <strong>Title:</strong> {{ $case->title }}<br> <strong>Description:</strong> {{ $case->description }}<br> <strong>Status:</strong> {{ $case->status }}<br> <strong>ID:</strong> {{ $case->id }}<br> <!-- Button to delete the case --> <button wire:click="deleteCase">Delete</button> </li> </ul> @else <p>No case found.</p> @endif </div> 我尝试更改 foreach 循环,但它仍然不起作用,我希望它能够检索提交的案例并使用 foreach 循环列出它们 试试这个。 始终将数据放入视图中。 1.manage-case.php组件 public function render() { // Load the Livewire view with the current user's cases $cases = Cases:all(); return view('livewire.manage-case',['cases'=>$cases]); }

回答 1 投票 0

为什么我使用 post 方法却收到 get method notsupported 错误(支持的方法:post)?

我正在尝试使用 Laravel 构建用户和客户端页面我创建了一个可用于创建用户的页面,现在我想在单击这些用户时创建一个类似的页面,但我不断...

回答 1 投票 0

如何使用 Dompdf 将 MySQL 数据库中的图像显示为 pdf

我尝试使用DomPDF在PDF中显示数据库中的图像后,它没有出现,并且加载速度很慢。 我的看法: 我尝试使用DomPDF以PDF格式显示数据库中的图像后,它没有出现,并且加载速度很慢。 我的看法: <div class="image"> <img src="{{ $logo }}" alt="Sample Image" style="height: 50px;"> </div> 我正在开发一个 Laravel 项目并使用 DomPDF 生成 PDF 证书。下面的代码来自我的CertificateController,它处理这些证书的生成: namespace App\Http\Controllers; use App\Models\Certificate; use App\Models\Term; use Illuminate\Http\Request; use PDF; use Auth; // Import the Auth facade use Barryvdh\DomPDF\PDF as DomPDFPDF; use Illuminate\Support\Facades\Auth as FacadesAuth; use Illuminate\Support\Facades\Storage; class CertificateController extends Controller { public function generateCertificate($termId) { // Fetch the term and relevant data $term = Term::find($termId); // Check if the term and necessary data are available // Get the authenticated user's name $userName = FacadesAuth::user()->name; $userLastName = FacadesAuth::user()->last_name; // Fetch the certificate data, including the logo URL $certificate = Certificate::first(); // Prepare data for the certificate template $data = [ 'username' => $userName, // Use the authenticated user's name 'userlastname' => $userLastName, 'course' => $term->course->title, // Assuming that 'course' is a property of the Term model 'term' => $term->title, // Assuming that 'title' is a property of the Term model 'date' => $term->finish_date, // Assuming that 'title' is a property of the Term model 'logo' => asset('storage/' . $certificate->logo), 'position_1' => $certificate->position_1, 'position_2' => $certificate->position_2, 'name_1' => $certificate->name_1, 'name_2' => $certificate->name_2, ]; // Load the certificate template HTML $html = view('certificate.certificate', $data)->render(); // Generate the PDF from the HTML $pdf = PDF::loadHTML($html); // Set the paper size to certificate size (e.g., A4) and landscape orientation $pdf->setPaper('Letter', 'landscape');; // Set the file name for the PDF $fileName = 'certificate_' . $term->id . '.pdf'; // Optionally, you can store the PDF on the server or force download // Example: $pdf->save(storage_path('certificates/' . $fileName)); // Example: return $pdf->download($fileName); // Display the PDF in the browser return $pdf->stream($fileName); } // Method to handle the form submission public function index() { $certificate = Certificate::first(); // Retrieve a single certificate return view('contents.admin.badges.index', compact('certificate')); } } 要在 Laravel 中使用 DomPDF 以 PDF 形式显示 MySQL 数据库中的图像,您可以按照以下步骤操作: 确保您已安装所需的软件包: DomPDF:作曲家需要 barryvdh/laravel-dompdf Laravel Collective HTML 包:composer require laravelcollective/html 确保您的数据库表包含用于存储图像数据的列。您可以使用 BLOB(二进制大对象)数据类型来存储图像。 在你的 Laravel Blade 视图(例如,certificate.blade.php)中,你可以使用 Laravel Collective HTML 包的 image 方法来显示图像。 这是您的证书控制器的更新代码: namespace App\Http\Controllers; use App\Models\Certificate; use App\Models\Term; use Illuminate\Http\Request; use PDF; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; class CertificateController extends Controller { public function generateCertificate($termId) { // Fetch the term and relevant data $term = Term::find($termId); // Check if the term and necessary data are available // Get the authenticated user's name $userName = Auth::user()->name; $userLastName = Auth::user()->last_name; // Fetch the certificate data, including the logo $certificate = Certificate::first(); // Prepare data for the certificate template $data = [ 'username' => $userName, 'userlastname' => $userLastName, 'course' => $term->course->title, 'term' => $term->title, 'date' => $term->finish_date, 'logo' => Storage::disk('public')->url($certificate->logo), // Use the Storage facade to get the URL 'position_1' => $certificate->position_1, 'position_2' => $certificate->position_2, 'name_1' => $certificate->name_1, 'name_2' => $certificate->name_2, ]; // Load the certificate template HTML $html = view('certificate.certificate', $data)->render(); // Generate the PDF from the HTML $pdf = PDF::loadHTML($html); // Set the paper size to certificate size (e.g., A4) and landscape orientation $pdf->setPaper('Letter', 'landscape'); // Set the file name for the PDF $fileName = 'certificate_' . $term->id . '.pdf'; // Optionally, you can store the PDF on the server or force download // Example: $pdf->save(storage_path('certificates/' . $fileName)); // Example: return $pdf->download($fileName); // Display the PDF in the browser return $pdf->stream($fileName); } // Method to handle the form submission public function index() { $certificate = Certificate::first(); // Retrieve a single certificate return view('contents.admin.badges.index', compact('certificate')); } }

回答 1 投票 0

如何使 Laravel (Blade) 文本字段只读

我有一个文本框需要设为只读;我不想使用 array('disabled' => 'true') 因为我需要 PHP 来处理该字段: {{ Form::text('login_token', Worker::generateLoginToke...

回答 7 投票 0

图像未在 Laravel Blade 中显示

我正在开发一个简单的 Laravel 项目,我想在 Laravel Blade 中显示公共目录中的图像,但它显示的是空白屏幕而不是图像,下面是屏幕...

回答 3 投票 0

如何向警报刀片模板添加响应?

在我的 UserController 中我有以下行: if (!Gate::check('can:main_page')) { return response(['error' => ['status' => 403, 'message' => '您无法访问此页面...

回答 1 投票 0

Laravel Blade 检查用户是否在权限数组中没有权限

你们能帮我吗?我只是想知道如何检查用户是否没有 laravel Blade 上的权限数组的权限。我认为是@canany的反面 也许插图中...

回答 1 投票 0

从控制器接收到的数据显示“bootstrap-table”中的数据

从 Laravel 中的控制器我以这种方式将数据发送到视图 公共静态函数index():工厂|视图 { $products = Products::where('visible',true)->get(); 返回

回答 1 投票 0

Laravel 复选框值更新

我是 Laravel 新手,我想做一个简单的复选框练习。我想输入已批准的默认值为 1。如果我单击该复选框,该值将设置为 2。 我是 Laravel 新手,我想做一个简单的复选框练习。我想输入 approved 的默认值为 1。如果我单击复选框,该值将设置为 2。 <input type="hidden" name="approved" value="1"></input><input type="hidden" name="checkbox" value="2"></input> 这是我的脚本,用于将 Ajax 中的 approved 值传递给控制器: approved:$('input[name=approved]').val(), 这是我的控制器: $approved = $request->approved; 结果是无论我是否点击复选框,值始终是1。你能帮我弄清楚吗? 你需要改变一些事情...... <input type="checkbox" name="approved" value="2" {{ old('approved', 1) == 2 ? 'checked' : '' }}> approved: $('input[name="approved"]:checked').val() $approved = $request->input('approved', 1);

回答 1 投票 0

laravel:无法从blade中的复选框接收选中的值

我是 Laravel 新手。我想做一个简单的复选框练习。我想输入已批准的默认值是1,如果我单击该复选框,该值将设置为2。 这是我的标记: 我是 Laravel 新手。我想做一个简单的复选框练习。我想输入 approved 的默认值为 1,如果我单击该复选框,该值将设置为 2。 这是我的标记: <input type="hidden" name="approved" value="1"></input><input type="hidden" name="checkbox" value="2"></input> 这是我的脚本,用于将 ajax 中的 approved 值传递给控制器: approved:$('input[name=approved]').val(), 这是我的控制器: $approved = $request->approved; 结果是:无论我是否点击复选框,该值始终为1。你能帮我算一下吗?非常感谢! 你需要改变一些事情...... <input type="checkbox" name="approved" value="2" {{ old('approved', 1) == 2 ? 'checked' : '' }}> approved: $('input[name="approved"]:checked').val() $approved = $request->input('approved', 1);

回答 1 投票 0

Laravel 10x:如何访问原始 HTML 中的 env 变量? [重复]

我有一个刀片页面,显示来自我的数据库的 HTML 内容: {!! $html内容!!} 这段代码很好地渲染了 HTML。 但在该变量内,我使用的是这样的刀片代码: 我有一个 blade page,它显示来自我的 Database: 的 HTML 内容 {!! $htmlContent !!} 这段代码很好地渲染了 HTML。 但是在该变量内部,我使用的是这样的刀片代码: <a href="{{ env('app_url') }}/shares"><img src="{{ asset('asset/img/shares.png') }}" /></a> 问题是链接(不起作用)和图像都没有出现。 如何解决这个问题? 要解决此问题,您可以在显示 HTML 内容之前使用 str_replace 函数将这些 Blade 指令替换为其实际值。以下是如何做到这一点的示例: // Get the HTML content from the database $htmlContent = // Fetch your HTML content from the database here // Replace Blade directives with their actual values $htmlContent = str_replace('{{ env('app_url') }}', config('app.url'), $htmlContent); $htmlContent = str_replace('{{ asset('asset/img/shares.png') }}', asset('asset/img/shares.png'), $htmlContent); // Display the HTML content {!! $htmlContent !!}

回答 1 投票 0

如何使用 jQuery 在每次单击按钮后调用 Dropzone 的 init 函数?

我有一个使用 for 循环创建的类似 元素的列表。对于每个 元素,我都有一个用于编辑信息的按钮。每次单击此编辑按钮时,都会弹出一个... 我有一个使用 <div> 循环创建的类似 for 元素的列表。对于每个 <div> 元素,我都有一个用于编辑信息的按钮。每次单击此编辑按钮时,都会打开一个弹出窗口,其中包含 Dropzone 框(使用 Dropzone 库)。现在,要加载与每个 <div> 相关的图像,我使用 jQuery 更改与图像 ID 关联的输入值。 但是,我需要从输入中读取更改后的 ID 并在 Dropzone 的 init 函数中使用它。问题在于 Dropzone 是在更改输入值之前创建的,并且在初始页面加载期间,它具有空值。我想在每次单击编辑按钮后以与前一个相同的配置重新运行 Dropzone init 函数。 我现在将发布代码片段以供参考。 HTML 文件: @foreach($steps as $step) <div class="row card p-3 mb-3 d-flex justify-content-center"> <div class="col-12 row justify-content-between align-self-center mb-2"> <div class="col-6 p-0"> <button type="button" class="btn update_step" title="update" data-toggle="modal" data-target="#update_step_modal" step_number="{{$step->number}}" route="{{route('panel.contents.clusters.steps.update', [$content->id, $cluster->id, $step->id])}}"> <span class="mdi mdi-18px mdi-square-edit-outline"></span> </button> </div> </div> <div class="col-12 row justify-content-center align-self-center mb-2"> <p class="col-12 step_description_p">{{$step->description}}</p> <div class="col-6 justify-content-center pt-4"> <input class="step_cover_id" value="{{$step->cover_id}}" hidden> <img src="{{$step->cover_image}}"> </div> </div> </div> @endforeach 模态 HTML 文件: <div class="modal fade" id="update_step_modal" tabindex="-1" role="dialog" aria- labelledby="update_step_modal" aria-hidden="true" data-keyboard="false" data- backdrop="static"> <div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> <div class="col-12 row justify-content-center align-self-center"> <form action="" method="POST" id="update_step_form"> @method('PATCH') @csrf <textarea name="description" id="update_step_description"></textarea> <input name="cover_id" id="update_step_cover_id" hidden> <input name="video_id" id="update_step_video_id" hidden> </form> </div> <div class="col-12 row justify-content-center align-self-center mb-2"> <div class="col-6" id="update_step_cover_div"> <form action="{{url('panel/upload')}}" method="POST" class="dropzone" id="update_step_cover_form"> @csrf <input name="type" value="step_cover" hidden /> <input name="content_id" value="{{$content->id}}" hidden /> <input name="cluster_id" value="{{$cluster->id}}" hidden /> <div class="dz-message" data-dz-message> <span class="m-dropzone__msg-desc">some messages</span> </div> </form> </div> </div> <div class="d-flex justify-content-center"> <button type="button" class="btn" id="step_update_button"> <span class="ladda-label">update</span> <span class="ladda-spinner"></span> </button> </div> </div> </div> </div> </div> JavaScript 文件: $('.update_step').on('click', function () { let step_number = $(this).attr('step_number') let route = $(this).attr('route') $('#edited_step_number').text(step_number) $('#update_step_form').attr('action', route) let parent = $(this).parent().parent().parent(); let description = parent.find('.step_description_p').text(); let cover_id = parent.find('.step_cover_id').val(); let video_id = parent.find('.step_video_id').val(); $('#update_step_description').val(description).change(); $('#update_step_cover_id').val(cover_id).change(); $('#update_step_video_id').val(video_id).change(); }); Dropzone.options.updateStepCoverForm = { paramName: "file", uploadMultiple: false, acceptedFiles: "image/*,", maxFiles: 1, headers: { 'X-CSRF-Token': $('input[name="_token"]').val(), 'Accept': 'application/json' }, addRemoveLinks: true, init: function() { let coverDropzone = this; let id = $('#update_step_cover_id').val() if(id !== ''){ $.ajax({ url: '/panel/fetch_file/' + id, type: 'get', dataType: 'json', success: function (response) { var mockFile = {name: response.data.file_name, size: response.data.size}; coverDropzone.emit("addedfile", mockFile); coverDropzone.emit("thumbnail", mockFile, response.data.file_path); coverDropzone.emit("complete", mockFile); coverDropzone.options.maxFiles = 0; } }); } this.on("removedfile", file => { let id = $('#update_step_cover_id').val() remove_file_function(id, "update_cover") }); }, accept: function(file, done) { done(); }, success: function (file, response) { $('#update_step_cover_id').val(response.data.id).change(); }, error: function (file, response) { error_function(file, response) } }; 重新初始化 Dropzone 以反映新的输入值 您正在处理修改 cover_id 输入值后更新 Dropzone 组件的挑战。这里的问题是 Dropzone 组件仅在其初始设置期间读取输入字段值。如果您稍后更改输入值,例如单击 update_step 按钮时,Dropzone 将无法识别此更改,除非您重新初始化它。 动态创建 Dropzone 组件: 您可以选择根据需要动态制作和拆除 Dropzone 组件,而不是通过 Dropzone.options.updateStepCoverForm 坚持 Dropzone 的声明性设置。 单击按钮时重新初始化 Dropzone: 配置输入值后,每次按 update_step 按钮时,您都会继续删除之前的 Dropzone(如果有),然后继续生成新的 Dropzone。这种方法可确保新创建的 Dropzone 的 init 函数能够识别更新的输入值。 更新代码: // Remove this static configuration // Dropzone.options.updateStepCoverForm = { ... }; // Variable of the current Dropzone instance let coverDropzone; $('.update_step').on('click', function() { // TODO: [your previous code here] // After setting the new input values reinitialize Dropzone initializeDropzone(); }); function initializeDropzone() { // If there is already an existing Dropzone instance it gets destroyed if (coverDropzone) { coverDropzone.destroy(); } // Creates a new Dropzone instance coverDropzone = new Dropzone("#update_step_cover_form", { paramName: "file", uploadMultiple: false, acceptedFiles: "image/*,", maxFiles: 1, headers: { 'X-CSRF-Token': $('input[name="_token"]').val(), 'Accept': 'application/json' }, addRemoveLinks: true, init: function() { // TODO: [put your existing init function code here] }, accept: function(file, done) { done(); }, success: function(file, response) { $('#update_step_cover_id').val(response.data.id).change(); }, error: function(file, response) { error_function(file, response); } }); } initializeDropzone(); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 更新: 很可能会出现您提到的问题,因为即使您已经销毁并重新初始化了 Dropzone 实例,由前一个实例创建的 DOM 元素(即之前获取的文件预览)可能仍然存在。 要解决此问题,您可以在销毁 Dropzone 实例时手动消除预览。 下面是代码的更改版本,应处理预览的清除: 您修改后的代码: $('.update_step').on('click', function () { ... ... // Your previous code stays here // Destroys previous Dropzone instance if (Dropzone.instances.length > 0) { const dropzoneInstance = Dropzone.forElement("#update_step_cover_form"); // Clears the previews dropzoneInstance.removeAllFiles(true); dropzoneInstance.destroy(); } // Reinitializes the Dropzone with updated configurations new Dropzone("#update_step_cover_form", { ... ... // The rest of your Dropzone configurations stay here }); });

回答 1 投票 0

laravel 如何在刀片模板中向数组添加元素

我想将元素添加到 laravel Blade 模板中的数组中。这是我的脚本: 选定的_arr = []; 我想要一个像[1,2,3]这样的数组,我尝试使用array_push,th...

回答 1 投票 0

调用控制器功能重定向到空白页面

我认为有几个字段集,每个字段集都有一个提交按钮 ... 我的视图中有几个字段集,每个字段集都有一个 submit 按钮 <button class="next action-button" type="submit" name="next" data-gotostep="3">(Save & Next)</button> 按钮调用此路线 Route::get('worksteps/store/{subprocess_id}', 'WorkstepsController@store')->name('worksteps.store'); 存储功能 public function store(StoreWorkstepRequest $request) { $created_by_id = Auth::user()->id; $value = $request->target_value; $unit = $request->unit; $subprocess_id = $request->subprocess_id; $step_position = $request->subprocess_step_position; $step_system_id = $request->subprocess_system_id; $registry_date = Carbon::now()->toDateTimeString(); DB::table('subprocess_registry')->updateOrInsert( ['subprocess_id' => $step_system_id], ['value' => $value, 'unit' => $unit, 'step_position' => $step_position, 'created_at' => $registry_date, 'created_by_id' => $created_by_id, ] ); return back(); } 一切都按预期工作,除了重定向到空白页的return back();行 我只需要调用 store 方法而不返回任何内容,也不对视图进行任何更改。 尝试过 return back(); return redirect()->back(); return redirect()->previous(); 他们都重定向回空白页面,还尝试完全删除 return 语句。 如何在后台调用 store 函数而不影响 view? 您可以使用 AJAX 来实现: 首先添加jquery: 将按钮类型更改为按钮,这样它就不会尝试以传统方式提交表单: <button class="next action-button" type="button" name="next" data-gotostep="3">(Save & Next)</button> AJAX 提交: $(document).ready(function() { $('.next.action-button').on('click', function() { var subprocess_id = $(this).data('gotostep'); // Retrieve subprocess_id from the button data attribute $.ajax({ url: '/worksteps/store/' + subprocess_id, type: 'GET', data: { target_value: $('input[name="target_value"]').val(), unit: $('input[name="unit"]').val(), subprocess_id: $('input[name="subprocess_id"]').val(), subprocess_step_position: $('input[name="subprocess_step_position"]').val(), subprocess_system_id: $('input[name="subprocess_system_id"]').val(), }, success: function(response) { console.log(response); }, error: function(xhr, status, error) { console.error(error); } }); }); }); 在你的控制器中你应该返回 JSON: return response()->json(['status' => 'success', 'message' => 'Data saved successfully']);

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.