Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7775811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:43:12+00:00 2026-06-01T17:43:12+00:00

I was going to ask this question (until I found it was already asked)

  • 0

I was going to ask this question (until I found it was already asked) and now have the answer to that question:

It’s better to request JSON from a PHP script and then wrap the results in HTML with JavaScript.

Now I have the unfortunate task of generating HTML with JavaScript to append to my document and am not sure how best to approach this.

With PHP I could simply store a HTML file and then use file_get_contents() and regex to replace some tokens with the relevant information, however I don’t think it’s that easy with JavaScript.

Some methods I have thought of:

  1. The repulsive approach. Generate a massive ugly string and then append that:

    var html = '<div class="comment">' +
        '<strong>' + author + '</strong>: ' +
        '<p>' + content + '</p>' +
    '</div>';
    
    $("#comments").append(html);
    
  2. Store the string somewhere and then use regex on that, which might look like this:

    var commentHTML = '<div class="cmt"><strong>{auth}</strong>: {cmt}</div>';
    

Is there a library/plugin that deals with this better maybe? Riddling my JavaScript with chunks of HTML stored in strings is something I’d really like to avoid. Maybe there is a similar method to what I mentioned I do using PHP? Can JavaScript read HTML files and store the content as a string?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:43:13+00:00Added an answer on June 1, 2026 at 5:43 pm

    Congrats, you just invented Mustache.js. Check it out: https://github.com/janl/mustache.js

    var data = { author: "An Author", content: "Some content" };
    var template = "<div class='cmt'><strong>{{author}}</strong>: {{comment}</div>";
    var html = Mustache.render(template, data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know the question I'm going to ask is already asked for by other
I have a feeling that I am going to ask a stupid question, yet
I'm going to re-ask this question in a slightly different way. Say I have
I'm going to ask and answer this question because it took me forever to
This question was asked a few years ago, so I'm going to ask it
I don't know how to ask this question that's why I'm going to simulate
I am going to ask you this question here since I cannot find answer
I was going to ask this in tigris.org, however they have maintenance in their
I am going to ask a question that might sound weird. Is there a
I'm going to ask this question again,I thought I had figured it out but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.