Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would go with creating an HTML structure that contains placeholders for the elements you'll need to update via AJAX. How much structure it applies will depend on what you're updating; if you know the number of elements you'll have ahead of time, it would be something to the effect of </p> <pre><code>&lt;div id="article1"&gt; &lt;div id="article1Headline"&gt;&lt;/div&gt; &lt;div id="article1Copy"&gt;&lt;/div&gt; &lt;div id="article1AuthorInfo"&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="article2"&gt; &lt;div id="article2Headline"&gt;&lt;/div&gt; &lt;div id="article2Copy"&gt;&lt;/div&gt; &lt;div id="article2AuthorInfo"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>You then write code that references the id of each element directly, and inserts into the .innerHTML property (or whatever syntactically more sugary way jquery has of doing same thing). IMHO, it's not really so terrible to have to assign the contents of each element, the part that you don't want to have to sprinkle through your AJAX functions is the HTML structure itself; in your app the content is volatile anyway.</p> <p>However, it looks like you might have a list of an unknown number of elements, in that case it may be that you'd need to just put in a placeholder:</p> <pre><code>&lt;div id="articleList"&gt;&lt;/div&gt; </code></pre> <p>In that case I don't really see a way to avoid building the HTML structure in the javascript calls, but a reasonable amount of decomposition of your javascript should help that:</p> <pre><code>function addArticle( headline, copy, authorInfo, i ){ createDiv( "article" + i + "Headline", headline ); createDiv( "article" + i + "Copy", copy); createDiv( "article" + i + "AuthorInfo", authorInfo ); } </code></pre> <p>(not working code of course, but you get the idea,)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload