jquery - posting a single dimenstion array to db ajax post -
jquery - posting a single dimenstion array to db ajax post -
i have form, loads details using jquery load function here form
<form id="form1" name="form1" method="post" action=""> <div id="tablebg"> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="list"> <thead> <tr> <th width="39%" scope="col">white list</th> <th width="61%" scope="col"> </th> </tr> </thead> </table> <div style="max-height:400px; overflow-y:auto"> <table width="100%" border="0" cellspacing="0" cellpadding="0" id="list"> <tr class="sub_head"> <td scope="col"><strong>reg. no.</strong></td> <td scope="col"><strong>student name</strong></td> <td scope="col"><strong>grade</strong></td> <td scope="col"><strong>message id</strong></td> </tr> <tbody></tbody> </table> </div> <div id="pagefooter"> <input type="submit" name="save_result" id="save_result" value="save results" /> </div> </div> </form>
and loads loads code below page
do{ ?> <tr <?php echo (($x%2) != 0) ? '' : ' class="alternate-row row"' ?>> <td scope="col"><?php echo $learners['reg_no'];?></td> <td scope="col"><?php echo $learners['surname']." ".$learners['full_names']." (".$learners['nickname'].")";?></td> <td scope="col"><?php echo $learners['grd']." ".$learners['grade_section'];?></td> <td scope="col"> <input name="sms_id[<?php echo $learners['reg_no']; ?>]" type="text" size="3" /> </td> </tr> <?php $x++;}while($learners = $getlearners->fetch());
this code within form , there submit button @ bottom. posted process.php next code, print's output
if(isset($_post['submit'])){ foreach($_post['sms_id'] $reg=>$msg_id){ echo $reg. " / ".$msg_id; }
}
the above displays both values if form posted straight form process.php
but wanted utilize ajax , tried next code not working. posting $msg_id not other value.
var formdata = $("#form1").serializearray(); $.ajax({ url: "models/process.php", type: "post", data: formdata, success: function(data) { alert(data); } });
this code not working can help? in advance.
j d k
actually, checking if(isset($_post['submit']))
in process.php not passing ajax.
$('#form1').serializearray()
doesn't include info submit button.
check documentation here: http://api.jquery.com/serializearray/
your php code (process.php) should changed to:
//if(isset($_post['submit'])){ // not available when using .serializearray() foreach($_post['sms_id'] $reg=>$msg_id){ echo $reg. " / ".$msg_id; } //}
jquery html ajax forms serializearray
Comments
Post a Comment