执行ajax后返回刀片



我正在尝试在ajax响应ok后加载@include()刀片到laravel中的其他刀片。我正在做一个统计选项卡窗格,我需要发送数据到我的控制器,为此我正在做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]);
}

这个函数返回我需要的所有数据。但我希望不要重载我的页面,并在此视图中生成图形。

我正在执行此操作,不返回错误,但不返回任何内容。我在谷歌上阅读,很多人说使用->render(),但我无法显示结果

谢谢你的帮助和自述

如果你的模板中有一个div,你想在那里显示这个刀片视图,你可以这样做:

$("#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);
}
});
})

最新更新