javascript - Ajax to get input textbox array and display the result to a div -
this display form
<form name='foodlist' action='checkout' method='post'> <table> <tr> <td>product name</td> <td>price</td> <td>quantity</td> <td>amount</td> </tr> <tr> <td><input type='text' name='foodname[]' size='10' class='foodname' /></td> <td><input type='text' name='price[]' size='2' class='price'/></td> <td><input type='text' name='qty[]' size='2' class='qty'/></td> <td><input type='text' name='amt[]' size='2' class='amt'/></td> </tr> <tr> <td><input type='text' name='foodname[]' size='10' class='foodname' /></td> <td><input type='text' name='price[]' size='2' class='price'/></td> <td><input type='text' name='qty[]' size='2' class='qty'/></td> <td><input type='text' name='amt[]' size='2' class='amt'/></td> </tr> </table> </form>
i have ajax jquery input values.
$.ajax({ type : "post", url : "ajaxfood.php", data: $('[name="qty[]"]').serialize(), success : function(html) { alert (html); } });
this php:
<?php $qtys = $_post['qty']; echo json_encode($qtys); ?>
the above code working , displaing qty array. problem want textboxes in php. tried send while form won't worked
data: $('form').serialize(),
- what way send whole form data.
- and how php.
- and how put result in div.
my first question important me. please help
try using $('form').serializearray()
ajax data in js. if you're on new version of chrome, can use console in dev tools (f12) view output in table with:
var formarray = $('form').serializearray(); console.table(formarray);
if see info in there, should available in php $_post
variable server-side code. use same var_dump()
call on server make sure it's there. - http://jsfiddle.net/rsrj07fn/
this information server, , print out on server make sure it's there. var_dump()
not finished product, debugging purposes visually see assigned server side variables (like $_post
). if want use string values of data made server, should able use, example:
echo $_post['foodname'][0]; echo $_post['foodname'][1]; echo $_post['price'][0]; echo $_post['price'][1];
etc.
to put them in 1 div:
echo "<div>"; echo $_post['foodname'][0]."<br>"; echo $_post['foodname'][1]."<br>"; echo $_post['price'][0]."<br>"; echo $_post['price'][1]."<br>"; echo $_post['qty'][0]."<br>"; echo $_post['qty'][1]."<br>"; echo $_post['amt'][0]."<br>"; echo $_post['amt'][1]."<br>"; echo "</div>";
Comments
Post a Comment