gpt4 book ai didi

javascript - 更新 td 的值而不需要重新加载页面

转载 作者:行者123 更新时间:2023-12-01 03:25:59 26 4
gpt4 key购买 nike

当我使用 AJAX 更改某些患者的状态时,我需要更改 <td> 显示的值直接设置为从下拉列表中选择的相同值:

$(document).on('change', '#patient_status ', function()
{
if(confirm("Are you sure you want to change the status of a patient ?"))
{
var pid = $(this).closest('tr').attr('id');
var new_status = $("#patient_status").val();
$(this).closest('tr').find('#change_status').val(new_status);
//console.log(pid + " " + new_status);
$.ajax({
url: '../php/changeStatus.php',
type: 'POST',
dataType: 'TEXT',
data: {pid: pid, new_status: new_status},
beforeSend:function(){
$('#wait').show();
},
success:function(resp){

},
error:function(resp){

},
complete:function()
{
$('#wait').hide();
}
})
}
});

下图给出了一个示例,其中我将患者的状态从活跃状态更改为默认状态,数据库中的值已更改,但在屏幕上我需要重新加载页面。

我认为错误在这一行:

$(this).closest('tr').find('#change_status').val(new_status);

html 表单在这里:

<tr id="<?php echo $patient['patient_id']; ?>">
<td id="change_status"><?php echo $patient['patient_status']; ?></td>
<tr>

最佳答案

ajax成功后你可以这样做:

success:function(resp){
$('#td _id').html(change_status_value);// just a demo
},

关于javascript - 更新 td 的值而不需要重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44824835/

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