I am creating a table displaying user's account details. In this table I am managing a user's account. Now i wish to display the updated value of accountStatus in the TD with class accountStatus.
foreach ($result_val->result() as $row) {
$accountStatus = array('data' =>$row->accountStatus,'class' => 'accountStatus');
$this->table->add_row($row->username,$row->email,$accountStatus,(($row->accountStatus == 'deleted')? " " :"<input type=\"button\" id=".$row->userID." class=\"btn btn-warning btn-small block\" value=\"Block\"> <input type=\"button\" id=".$row->userID." class=\"btn btn-success btn-small activate\" value=\"Activate\"> <input type=\"button\" id=".$row->userID." class=\"btn btn-danger btn-small delete\" value=\"Delete\">"));
}
when clicked on any of the button in the last table column the userID and new accountStatus value is send to the controller using
function manage_user_account(userID,value){
$.post(url,{
userID : userID,
value : value
},
function(response){
if(response.status == 1000){
alert(response.accountStatus);
$(this).closest('tr').find('.accountStatus').html(response.accountStatus);
$("#headMsg").text('Account status has been successfully updated');
$("#headMsg").show();
}
else if(response.status == 1300){
$("#headMsg").text('Account status updation failed ! Try Again.');
$("#headMsg").show();
}
else if(response.status == 1200){
$("#headMsg").text('Web server error ! Try Again.');
$("#headMsg").show();
}
},'json');
}
But the value is not updated at the same time, it is displayed after reloading the page. Please help me with this.
this
is likely referring to the global window object. Pass event.target
from the click handler to your function:
$(foo).click(function(event) {
...
manage_user_account(id,val,event.target);
}
function manage_user_account(userID,value,button){
...
$(button).closest('tr').find('.accountStatus').html(response.accountStatus);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.