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

216
Vistas
How do you access and render html outside of javascript file without node?

*** Nobody could answer this question, so another hour of googling and the answer is the Mustache client side template engine.

Hope it helps someone.

I have done a fare bit of googling, about 6 hours worth, I can assure you that this question has never been answered properly.

If I have a JSON load of comments, what is the most elegant, clean, efficient way of returning the html elements to the page using javascript/jQuery?

For example;

jsonComments = {"comments": 
    [{"username":"bob", "location":"Earth", "comment":"hello"},
    {"username":"bob", "location":"Earth", "comment":"hello"},
    {"username":"bob", "location":"Earth", "comment":"hello"},
    {"username":"bob", "location":"Earth", "comment":"hello"}]

$.each( response.payload, function( i, val ) {
     var comment = "<div class='comments-wrapper'><div>" + username + "</div><div>" + 
location + "</div><div>" + comment + "</div></div>";
    $('#comments').append(comment);
});

that is absolutely hideous, I want that html to be on its own page tucked away somewhere outside of the function. For example, in php I would just use

foreach($comments as $comment) {
   ob_start();
   include('commentsBox.php');
   $comment = ob_get_contents();
   ob_end_clean();
   echo $comment;
}

and inside the commentsBox.php

<?php ?>
<div class="comments-wrapper">
    <div><?=$comment["username"]; ?></div>
    <div><?=$comment["location"]; ?></div>
    <div><?=$comment["comment"]; ?></div>
</div>

Need and tidy and beautiful. How do I achieve the same results with javascript BESIDES using anything to do with node.js, I am not skilled enough to go down that road yet. Is this possible?

Or is there a nice way to do while still using php and javascript together, without like I said adding all the html to a json and returning it that way, cause thats just gross as well.

Thanks

about 4 years ago · Santiago Gelvez
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