I have a form which contains a table which is populated with data dynamically according to selected option in dropdown.
The dropdown contains 2 values "enabled" and "disabled". The first column of each row in table contains a checkbox. The table structure is as follows.
[checkbox ]| user | status
[checkbox1]| jim | enabled
[checkbox2]| sam | disabled
The checkbox value is equal to userid.
There is a button for changing the status of selected users.
on button click the selected checkbox value are posted using ajax and status of selected users are changed but the data is only refreshed on page reload.
How can I refresh the table when the status is changed. Here is my script.
function Status(){
var checked = []
$("input[name='select[]']:checked").each(function ()
{
checked.push(parseInt($(this).val()));
});
if(checked!=''){
$.ajax({
type:'post',
url:site_url()+'/common/changeStatus',
data:{'checked':checked},
dataType:'json',
async:false,
success:function(result){
if(result!= "false"){
$.msgBox({
title:"Success",
content:"Status change successful"
});
$(function () {
$('.msgButton').click(function (event) {
event.preventDefault();
$("#table").load($(this).attr("#table"));
});
});
}
Here #table
is the id of the table containig the data.
You have to construct the table with current status in PHP file itself. Then you can send it as response. In the Jquery AJAX response you have to add like this,
$(".table").html(resultTable);
resultTable is the response you are passing from PHP file. If you do like this only, you can get the table with the updated statuses.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With