I am working on php and jquery with one dropdown with companies. i
want to display particular companies all employees on select that
company. for this i am using ajax response with jquery. my reponse
shows me perfect data but my each function is not working correctly.
it shows me only last record from db.
$.ajax({
method: "GET",
dataType: 'json',
url:"getdata.php?id="+emp_id,
success:function (response){
$.each(response, function( index, value ) {
$(".bodytable").empty();
$("table.table").append("<tr><td>" + value.emp_name + "</td><td>" + "</td><td><input type='file'></td></tr>");
});
},
});
My response shows me correct data.
for e.g where i am having 2 employees it shows me [object object][object object]
if i am having 1 employee its shows me [object object].
But its not working inside each function. inside each function it only shows last record from database.
My html of company list:
<select id="billing_com" name="billing_com" >
<option>--Select Customer--</option>
<?php foreach($com_data as $key=>$eachcomData){
?>
<option value="<?php echo $eachcomData['com_id'];?>" <?php
if(isset($_GET['id'])){ echo ($upload['com_name'] == $eachcomData['com_id'])?'selected=selected':'abc'; } ?> >
<?php echo $eachcomData['com_name']; ?>
</option>
<?php }?>
</select>
code that will call after ajax response:
<table class="tabledata">
<thead>
<tr>
<th>Employee Name</th>
<th>Attach Payslip</th>
</tr>
</thead>
<tbody class="bodytable">
</tbody>
</table>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…