gpt4 book ai didi

javascript - 如何追加表中的值

转载 作者:行者123 更新时间:2023-11-30 00:08:43 25 4
gpt4 key购买 nike

我正在做一个日期范围表单字段,这里 console.log(fname) 意味着我得到了所有值,我想将这个值附加到一个表中 td,我正在尝试这种方法,但它不起作用,我如何在 td

中附加此值

     <div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" id="reservation">
</div>

<script type="text/javascript">
$(document).ready(function() {
$("#reservation").on("change", function() {
var reservation = $(this).val();
$.ajax({
type: 'post',
url: 'date-range.php',
data: {
logindate: reservation,
},
success: function(data) {
var res = jQuery.parseJSON(data); // convert the json
console.log(res);
if (res['status'] == "success") {

var htmlString = '';

$.each(res['data'], function(key, value) {

htmlString += '<tr>';
var ssm_id = value.ssm_id; // here i got ssmid
htmlString += '<td>' + value.ssm_id + '</td>';
$.ajax({
type: 'post',
url: 'config/functions.php',
data: {
ssm_id: ssm_id,
},
success: function(fname) {
console.log(fname); //here i got all names
// kani
// mahi
// kogila like this ans it will come console.log(fname),i want appent this value in hmlString+='<td>'+fname+'</td>';
htmlString += '<td>' + fname + '</td>'; // here value is not appending,nothing is happen
}
});

htmlString += '<td>' + 'Muthuraja' + '</td>';
htmlString += '<td>' + '20-05-2016' + '</td>';
htmlString += '<td>' + 'status' + '</td>';
htmlString += '<td>' + value.source + '</td>';
htmlString += '<td>' + "<span style='color:green'>View Profile</span>" + '</td>';

htmlString += '</tr>';
});
$('#datatable-editable > tbody').empty().append(htmlString);
} else {
$('#datatable-editable > tbody').empty().append("<center style='height:100px;padding-top:36px;color:red;font-size:17px;'><b>No matching records found</b></center>");
}
}
});
});
});
</script>


functions.php

<?php
$ssm_id = $_POST['ssm_id'];
if(!empty($ssm_id)){
echo firstname($ssm_id);
}

function firstname($id)
{
$f="SELECT firstname FROM register WHERE matri_id='$id'";
$rr=mysql_query($f);
while($row=mysql_fetch_array($rr))
{
$firstname = $row['firstname'];
}
return $firstname;
}

?>

最佳答案

只写成功部分。希望您能将其纳入工作结构。

success: function(data) {
var res = jQuery.parseJSON(data); // convert the json
console.log(res);
if (res['status'] == "success") {
$('#datatable-editable > tbody').empty();//emtpy tbody at the begining
$.each(res['data'], function(key, value) {
var htmlString = ''; //Place declaration inside each
htmlString += '<tr>';
var ssm_id = value.ssm_id; // here i got ssmid
htmlString += '<td>' + value.ssm_id + '</td>';
$.ajax({
type: 'post',
url: 'config/functions.php',
data: {
ssm_id: ssm_id,
},
success: function(fname) {
htmlString += '<td>' + fname + '</td>';
//move the whole set inside success of this ajax
htmlString += '<td>' + 'Muthuraja' + '</td>';
htmlString += '<td>' + '20-05-2016' + '</td>';
htmlString += '<td>' + 'status' + '</td>';
htmlString += '<td>' + value.source + '</td>';
htmlString += '<td>' + "<span style='color:green'>View Profile</span>" + '</td>';
htmlString += '</tr>';
$('#datatable-editable > tbody').append(htmlString);
}
});

});

}
}

关于javascript - 如何追加表中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37383665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com