Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Renderizar múltiples secciones de vista de hoja en la solicitud de ajax

Cuando la solicitud es ajax, renderizo la sección de contenido y la inserto en DOM. Está funcionando como se esperaba.

Sin embargo... no puedo encontrar la forma, cómo renderizar múltiples secciones, como content y title y más al mismo tiempo.

Controlador:

 public function awesome(Request $request) { if($request->ajax()){ return view('awesome')->renderSections()['content']; } return view('awesome'); }

Ajax y pushstate

 var load = function (url) { $.get(url).done(function (data) { $("#content").html(data); }) }; $(document).on('click', 'a[data-request="push"]', function (e) { e.preventDefault(); var $this = $(this), url = $this.attr("href"), title = $this.attr('title'); history.pushState({ url: url, title: title }, title, url); // document.title = title; load(url); });

diseños.app

 <title>@yield('title')</title> <meta name="description" content="@yield('desc')"/> <a data-request="push" title="AWESOME" href="<?= url('/'); ?>/awesome">Awesome</a> <a data-request="push" title="RANDOM" href="<?= url('/'); ?>/random">Random</a> <div id="content"> @yield('content') </div>

Espada:

 @extends('layouts.app') @section('title', 'Awesome') @section('desc', 'About awesome') @section('content') some text from awesome page @endsection

Pregunta:

¿Cómo renderizar ambos o más de ellos al mismo tiempo? ¿Debo usar una matriz o algo más? Por favor, dé un ejemplo o una explicación completa.

Gracias por cualquier respuesta.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Simplemente puede enviar un objeto json de título y contenido, y luego usar JS para analizar la matriz y extraer ambas secciones. Al igual que:

Controlador

 public function awesome(Request $request) { if($request->ajax()){ $view = view('awesome')->renderSections(); return response()->json([ 'content' => $view['content'], 'title' => $view['title'], ]); } return view('awesome'); }

Ajax y pushstate

 var load = function (url) { $.get(url).done(function (data) { $("#content").html(data.content); document.title = data.title; }) }; $(document).on('click', 'a[data-request="push"]', function (e) { e.preventDefault(); var $this = $(this), url = $this.attr("href"), title = $this.attr('title'); history.pushState({ url: url, title: title }, title, url); // document.title = title; load(url); });
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!