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

204
Views
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
});
about 4 years ago · Santiago Trujillo
1 answers
Answer question

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});
 ?>
about 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!