更新td的值而无需重新加载页面 [英] Updating a value of a td without the need to reload the page
本文介绍了更新td的值而无需重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用AJAX更改某些患者的状态时,我需要将<td>
显示的值直接更改为从下拉列表中选择的相同值:
When I change the status of some patients using AJAX I need to change the value that is displayed by a <td>
directly to the same value selected from drop list:
$(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();
}
})
}
});
下图显示了一个示例,其中我将患者的状态从活动状态更改为默认值,数据库中的值已更改,但在屏幕上我需要重新加载页面.
An example is presented by the following image where I changed the status of a patient from active to defaulter, the value changed in database but on screen I need to reload the page.
我认为错误在于这一行:
I think the error is in this line:
$(this).closest('tr').find('#change_status').val(new_status);
html格式在这里:
The html form is here:
<tr id="<?php echo $patient['patient_id']; ?>">
<td id="change_status"><?php echo $patient['patient_status']; ?></td>
<tr>
推荐答案
ajax成功后,您可以执行以下操作:
After ajax success you can do like this :
success:function(resp){
$('#td _id').html(change_status_value);// just a demo
},
这篇关于更新td的值而无需重新加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文