更新td的值而无需重新加载页面
当我使用AJAX更改某些患者的状态时,我需要将
$(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="">
在ajax成功之后你可以这样做:
success:function(resp){ $('#td _id').html(change_status_value);// just a demo },
首先使用class而不是id来表示多个元素。
例如:
其次用
$(this).html(new_status);
代替
$(this).closest('tr').find('#change_status').val(new_status);
- 获取新的MySQL条目并动态附加到现有div
- 使用json.stringify的MVC3 Controller null参数
- 如果我用空url调用jQuery.post()会发生什么?
- 通过Jquery Ajax调用创建TinyURL
- $ .ajax()和“Uncaught ReferenceError:数据未定义”
- 在Ajax jQuery中显示多个错误结果
- Ajax调用进入MVC Controller- Url问题
- Ajax与jQuery同步。 可能吗?
- 在jQuery UI对话框中加载和编辑数据
Interesting Posts