You can actually just pass a reference to the interval:
var interval_id;
interval_id = setInterval(function(){bid_button(id, interval_id); },1000);
function bid_button (id, interval_id) {
clearInterval(interval_id);
}
This works because the callback function in the interval is called later.
Keep in mind though that because of the way bid_button
is implemented some intervals may not get cleared. If you lose your internet connection for instance, it will keep trying and trying. The requests will resolve with status=0
.