简体   繁体   中英

Jquery Refreshing Div only once

I use jquery/ajax and php for active/deactive status, it works like when user clicks on active to turns into deactive and vice versa i'm able run this but ever time i click on active and deactive button it loads entire div section continuously.

my requirement is after click on active/deactive status the div should load only once and should stop recursively blinking for 2 to three times!

while($row = $data->fetch_arry(MYSQLI_ASSOC))
{ ?>
    <div>
        <?php if($row['status'] == '1'){?>
        <a class='btn btn-success active'></a>
        <?php else if($row['status'] == '0')?>
        <a class='btn btn-danger deactive'></a>
        <?php } ?>
    </div>
<?php } ?>

Jquery Code

$('body').delegate('.active','click',function(e){
    var IDstatus = 0;
    $.post('status.php',{
        status:IDstatus
    },function(e){
        $('#div_load').load('#div_load');
    })
})

$('body').delegate('.deactive','click',function(e){
    var IDstatus = 1;
    $.post('status.php',{
        status:IDstatus
    },function(e){
        $('#div_load').load('#div_load');
    })
})

I want only my #div_load should refresh once after changing my status!

Any help is appreciated Thanks!

Try to use the following

$(document).rady(function(){
$(".active").click(function(){
    $.ajax({
    url: "status.php",
    data:{status:1},
    dataType:'html',
    success: function(result){
         $('#div_load').html(result);
    }
    });
});$(".deactive").click(function(){
    $.ajax({
    url: "status.php",
    data:{status:0},
    dataType:'html',
    success: function(result){
         $('#div_load').html(result);
    }
    });
});

});

Don't use load()... it is like ajax. just pass the data from the server which you want to load inside the div

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM