views:

75

answers:

1

I am trying to get the div recentactivity to only refresh when Remove is clicked

< a href='#' onclick=\"javascript:remove_wall('$id')\">Remove

but when every i click on the link it keeps trying to refresh. when the mouse go's over the tr a link comes up saying remove here is the code for that.

$(function() {

$("tr").hover(function() {

var id = this.id.split('_').pop();       
$("#remove_" + id).show();    
}, function() {       
var id = this.id.split('_').pop();       
$("#remove_" + id).hide();

});

});

Here is what happened when you click the link.

function remove_wall(id) {

var refresh = setInterval(function() {

$("#recent_activity").load("activity.php?random=" +unique_requestid());
}, 1);

$("#contentArea").load("remove.php?wall_id="+id+"");

};

The remove in php is working perfectly fine.

A: 

The problem is you are using setInterval - which repeats a function every x milliseconds, where x is the interval given.

What you really need to use is setTimeout - which will start a timer and then run once the timer counts down, and will run only once.

Your code should look like this:

function remove_wall(id) {  
    var refresh = setTimeout(function() {
        $("#recent_activity").load("activity.php?random=" +unique_requestid());
    }, 1);
    $("#contentArea").load("remove.php?wall_id="+id+"");
};

Link for further reading: Timers with setTimeout and setInterval

phalacee
A Class ++++ Thank you
Gully