Laravel 11 AJAX 请求只显示响应数据,不执行成功函数

问题描述 投票:0回答:1

Laravel 11 AJAX 请求仅显示响应数据,而不执行 AJAX 中的成功函数。我已添加以下所有代码。

Index.blade.php:

<table id="employeesTable" class="table table-hover datatable">
    <thead>
        <tr>
            <th>ID</th>
            <th>Image</th>
            <th>Full Name</th>
            <th>Email</th>
            <th>Details</th>
            <th>Status</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>

    </tbody>
</table>

脚本:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
<script>
    $(document).ready(function() {

        fetchEmployees();

        function fetchEmployees() {
            $.ajax({
                url: '/system/employee',
                type: 'GET',
                dataType: "json",
                success: function(res) {
                    console.log(res.employees);
                }
            });
        }
    });
</script>

在控制器中:

public function index()
{
    $query = Employee::query();
    $employees = $query->orderBy('created_at', 'desc')
        ->get();

    return response()->json(["employees" => $employees]);
}

显示此内容的回复 --> 回复SS

我还没找到解决办法!

php ajax laravel laravel-blade laravel-11
1个回答
0
投票

运行 config:cache Artisan 命令来缓存配置文件:

php artisan config:cache

这将在 Laravel 应用程序的 bootstrap/cache 目录中生成一个缓存的配置文件 (config.php)。确保 Web 服务器可写入该目录。

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