Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rather than using IDs all the time, use jQuery context and classes:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ $("form").submit(function(e){ e.stopPropagation(); var form = $(this); // We're going to use this instead of all those IDs $.ajax({ type:"POST", url:"ajax_form_test2-json.php", data: form.serialize(), dataType:"json", success:function(msg){ $(".response", form) .removeClass('error') .addClass(msg.status); .html(msg.message); $(".name", form).html(msg.name); $(".description", form).html(msg.description); }, error:function(){ $(".response", form) .removeClass('success') .addClass('error') .html("There was an error submitting the form. Please try again."); } }); return false; }); }); &lt;/script&gt; </code></pre> <p>So, rather than this:</p> <pre><code>&lt;div id="static_description_&lt;?php echo $row_rsStatic['id']; ?&gt;" class="small_content"&gt;&lt;?php echo $row_rsStatic['description']; ?&gt;&lt;/div&gt; </code></pre> <p>You'll use a class instead:</p> <pre><code>&lt;div class="small_content description"&gt;&lt;?php echo $row_rsStatic['description']; ?&gt;&lt;/div&gt; </code></pre> <p>The approach:</p> <ul> <li>Use generic classes for your DIVs</li> <li>Use generic names for your INPUTs</li> <li>In your PHP <code>$_POST</code> handler, use the hidden ID field to know which record you're working with</li> <li>In your JSON response, use generic <code>status</code>, <code>message</code>, <code>name</code>, and <code>description</code> keys</li> </ul>
    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.
 

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