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 6675197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:49:28+00:00 2026-05-26T03:49:28+00:00

Suppose I got a div that uses AJAX to retrieve prices and information about

  • 0

Suppose I got a div that uses AJAX to retrieve prices and information about products, and appends the new products to current results.

<div id="product">
<div class="label">Price: <div class="price">$10.90</div></div>
<div class="label">Sales Price: <div class="price">$9.90</div></div>
</div>

I can do:
1) Get the price and data only. Then iterate through these results and have the Javascript create the div dynamically for each product.

Problem with this: If HTML structure for the div changes (say the class for price changes), I potentially need to change it in 2 places. In the static HTML, as well as in the Javascript.

2) Or is it better practice to have the server return the actual HTML to append to the page? But wouldn’t this be messy because the design isn’t separate from business logic, and the actual HTML structure might change?

Or is there a 3rd alternative I’m missing?

  • 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-05-26T03:49:28+00:00Added an answer on May 26, 2026 at 3:49 am

    You can use java-script side templating – there are lots of libraries. I will recommend looking at John Resig’s approach. I believe there is also work going on jquery based template engine.

    You may also read Rick Strahl’s experience here and also the comparison of various template libraries.

    Although java-script based templating is elegant solution to your problem, if you have to support java-script disabled scenario then your option #2 is good bet. Generally, you use server side templating to generate the html for first request as well as ajax request (so html structure is maintained only at one place i.e. server side template). Of course, in js-disabled scenarios, your ajax calls will become regular POST requests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this image to tell people that some action is loading: http://problemio.com/img/ajax-loader.gif Then
Suppose my javascript called server(AJAX call) and then got server response with an array
I've got a question about treating references to jQuery objects. Let suppose in my
I've got a php file that's suppose to do calculations on 2 inputs and
I have this div that's got a style attribute..In that I am setting it's
I got a div that expands on a click, sometimes its at the bottom
Suppose we got a code like this: IEnumerable<Foo> A = meh(); IEnumerable<Foo> B =
Suppose I got a file amended in two revisions, says 100, 110, in a
Suppose we got a original query as follows: SELECT A, B, C FROM tblA
Suppose I have got a model ArticleVersion in my project which is defined as:

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.