Note that there are some explanatory texts on larger screens.

plurals
  1. POProcessing AJAX response consisting of two logically separate HTML markup sections
    primarykey
    data
    text
    <p>I am having a data response consisting of two entirely separate sections from a presentation point of view but which are logically connected on the server side and therefore are more efficiently generated in one AJAX call. The two sections have to populate two separate divs. My question is what is the most optimal method to do this?</p> <p>OPTION1: Generate the response on the server side as:</p> <pre><code> &lt;div id="first_section"&gt; ... &lt;/div&gt; &lt;div id="second_section"&gt; ... &lt;/div&gt; </code></pre> <p>Load the response in a dummy div as in $('#dummydiv').html(response) and then extract individual sections as in $('#first_section).html() and $('#second_section).html() and use their return string to populate the target div as in</p> <pre><code> $('#target_div1').html( $('#first_section).html()); $('#target_div2').html( $('#second_section).html()); </code></pre> <p>OPTION 2: Write JS to process the response as one big string, use some regular expressions to parse and return the two separate sections as two individual strings to be assigned to the .html() of the target divs.</p> <p>OPTION 3: Have two separate AJAX calls, one for each div (expensive duplicate option as the server-side computing is very connected).</p> <p>OPTION 4: Any suggestions?</p> <p>Since this is something that I need to do consistently in the application, the right approach is very important. Any comments OR A DIFFERENT APPROACH ALTOGETHER will be appreciated.</p> <p><strong>UPDATE</strong>: The response is presentation (lot of markup generated on the server side to the data) and not data intensive. JSON would be a wrong choice I think as it would require markup to be generated on the client side. </p>
    singulars
    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. 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