Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
How to load website layout(header,footer) using js

I am newbie in javascript. I want to load my website main template file(header,footer,sidebar) using ajax. My layout file is given below.
layout.php

<?php
   $app = new App;
   $ret = $app->header();
   $ret .= $app->sidebar();
   $ret .= $app->footer();
   echo json_encode($ret);
?>

Now I want to load my layout file using ajax. As there is no div initially. How can I load this.My js file is given below.

$.ajax({
  url: 'layout.php',
  dataType: 'json',
}).done(function(resp){
  //here is problem
  //as initially no div is present
  //how can I load it with jquery
});
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can do this, looks fine. Don't forget the asynchronous of queries. So your code will:

$.ajax({
  url: 'layout.php',
  dataType: 'json',
}).done(function(resp){
  $('#content').html(resp.layout);
});

<?php
   $app = new App;
   $ret = $app->header();
   $ret .= $app->sidebar();
   $ret .= $app->footer();
   echo json_encode({layout: $ret});
 ?>
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda