Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This send all data in one (<strong>ajax</strong>) http request:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="http://code.jquery.com/jquery-1.5.1.min.js"&gt;&lt;/script&gt; &lt;script src="jquery.json-2.4.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function() { var id = 0; // Add button functionality $("table.dynatable button.add").click(function() { id++; var master = $(this).parents("table.dynatable"); // Get a new row based on the prototype row var prot1= master.find(".prototype").clone(); prot1.attr("class", "") prot1.find(".id").attr("value", id); master.find("tbody").append(prot1); alert(id); }); // Remove button functionality $("table.dynatable button.remove").live("click", function() { $(this).parents("tr").remove(); }); //Submit button clicked $('#button').click(function() { //$("table tr").has("th").remove(); var data = { final:{ value : [] } } $("table tbody tr").each(function() { // create an array of objects data.final.value.push({ id: $('.id', this).val(), wid: $('.WID', this).val(), ac: $('.ac', this).val(), tm: $('.tm', this).val(), cutt: $('.cutt', this).val() }); }); console.log(eval(data)); $.ajax({ async: false, url: 'receivearray.php', dataType: 'json', data: data, type: 'get' }); $('#myFrame1').attr("src", myarr3); }); }); &lt;/script&gt; &lt;style&gt; .dynatable { border: solid 1px #000; border-collapse: collapse; } .dynatable th, .dynatable td { border: solid 1px #000; padding: 2px 10px; width: 170px; text-align: center; } .dynatable .prototype { } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;table id="MyTable" class="dynatable"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;WID&lt;/th&gt; &lt;th&gt;InchargeName&lt;/th&gt; &lt;th&gt;Action&lt;/th&gt; &lt;th&gt;Time&lt;/th&gt; &lt;th&gt;&lt;button class="add"&gt;Add&lt;/button&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr class="prototype" id="pro"&gt; &lt;td&gt;&lt;input type="text" name="id[]" value="" class="id" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="name[]" value="" class="WID"/&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="col4[]" value="" class="ac" /&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="col3[]" value="" class="tm"/&gt;&lt;/td&gt; &lt;td&gt;&lt;button class="remove"&gt;Remove&lt;/button&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input type="button" id="button" value="submit"/&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Here <strong>receivearray.php</strong></p> <pre><code>&lt;?php file_put_contents('/tmp/temp.txt',var_export($_REQUEST['final'],true)); </code></pre>
    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