return blade 执行后 ajax

return blade after execute ajax

我正在尝试在 ajax 中响应正常后,在 laravel 中的其他 blade 中加载 @include() blade。我在选项卡窗格中进行统计,我需要将数据发送到我的控制器,为此我正在做 ajax 我有这个 ajax:

$("#createStatistcs").on('click', function(){
        let fromDate = $("#fromDate").val();
        let toDate = $("#toDate").val();
        let token = $('meta[name=csrf-token]').attr('content');

        $.ajax({
            type: 'GET',
            url: "{{ route('admin.llamadas.estadisticas') }}",
            data: { 'fromDate': fromDate, 'toDate': toDate },
            success: function(response){
                
            },
            error: function(xhr){
                alert(xhr.responseText);
            }
        });
    })

我的控制器里有这个:

public function index(Request $request)
    {
        $estadosLlamadas = EstadoLlamada::orderBy('desc')->get();

        if(isset($request->fromDate) && isset($request->toDate)){
            $fromDate = Carbon::parse($request->get('fromDate'));
            $toDate = Carbon::parse($request->get('toDate'));

            $fromDate = $fromDate->format('Y-m-d');
            $toDate = $toDate->format('Y-m-d');

        }else{
            $fromDate = new Carbon('first day of this month');
            $toDate = new Carbon('last day of this month');

            $fromDate = $fromDate->format('Y-m-d');
            $toDate = $toDate->format('Y-m-d');
        }

        $teleoperadoras = auth()->user()->whereIs('teleoperadora')->activos()->select(['id', 'nombre'])->orderBy('nombre', 'desc')->get();
        
        $array = [
            'toDate'   => $toDate,
            'fromDate' => $fromDate,
            'nombresEstados' => $estadosLlamadas->pluck('desc')->toArray(),
            'coloresEstados' => $estadosLlamadas->pluck('hex')->toArray()
        ];

        $query = Llamada::query()
            ->whereDate('llamada.created_at', '<=', $toDate)
            ->whereDate('llamada.created_at', '>=', $fromDate)
            ->whereIn('llamada.id_teleoperadora', $teleoperadoras->pluck('id'))
            ->join('users', 'llamada.id_teleoperadora', '=', 'users.id')->latest('llamada.created_at')->get();

        foreach($teleoperadoras as $teleoperadora) {
            $array['teleoperadoras'][] = $teleoperadora->nombre;
            $array['id_teleoperadoras'][] = $teleoperadora->id;
            $array[$teleoperadora->id]['resultados'] = [];
            $array['llamadas'][] = $query->where('id_teleoperadora', $teleoperadora->id)->count();

            $array['llamadasTodo'][$teleoperadora->id] = $query->where('id_teleoperadora', $teleoperadora->id);

            foreach($estadosLlamadas as $estado) {
                $array[$teleoperadora->id]['resultados'][] = $query->where('id_teleoperadora', $teleoperadora->id)->where('id_estado', $estado->id)->count();
            }
        }

        $array['nllamadas'] = $query->count();
        $roleUser = auth()->user()->getRoles()->first();

        $view = view('admin.llamadas.filtrado', [
                    'datos' => $array, 'estados' => $estadosLlamadas,
                    'teleoperadoras' => $teleoperadoras, 'roleUser' => $roleUser,
                ])->render();
        echo response()->json(['html'=>$view]);
    }

此功能 return 我需要的所有数据。但我希望不要重新加载我的页面并在此视图中生成图形。

我正在处理这个问题,没有 return 错误,但是 return 什么都没有。我在 google 阅读,许多人说使用 ->render() 但我无法显示结果

感谢您的帮助和自述

如果您的模板中有一个 div,您希望在其中显示此 blade 视图,您可以执行以下操作:

$("#createStatistcs").on('click', function(){
        let fromDate = $("#fromDate").val();
        let toDate = $("#toDate").val();
        let token = $('meta[name=csrf-token]').attr('content');

        $.ajax({
            type: 'GET',
            url: "{{ route('admin.llamadas.estadisticas') }}",
            data: { 'fromDate': fromDate, 'toDate': toDate },
            success: function(response){
                $('your-element').html(response.html);
            },
            error: function(xhr){
                alert(xhr.responseText);
            }
        });
    })