i have one setinterval method which call php script every 3 sec to check for new data.
setInterval($.proxy(function(){
var dataString = options.url+'table_id='+options.table_id
$.ajax({
type : 'POST',
url : options.url+"check",
data : dataString,
success: $.proxy(function(data){
if(data != ""){
var json = $.parseJSON(data);
if(json.num >= 1){
this.callOtherMethod(json.user_id);
}, this));
}
}
}, this)
});
}, this), 3000);
if num is >= 1 button will be displayed.
and if user click on add button the url from callOtherMethod loads so many times as the first method is called.
example:
if the user click on add button after 30 sec
example.com/add will be called 10 times.
my callOtherMethod
this.callOtherMethod = function(id)
{
this.id = id;
$('#button').show();
$(".add").bind('click', $.proxy(function(){
if(this.user_id > 0){
$.ajax({
type: "POST",
url: "add",
data: options.url+"text="+this.text+"&user_id="+this.user_id,
success: $.proxy(function(data){
if(data != ""){
// add action
}
}, this)
});
}
},this));
thank you for any help
the problem is that you are showing the button and doing the bind in the
callOtherMethodwhile you should only be assigning your newid. The$('#button').show()and$(".add").bind('click', $.proxy(function(){ ...should be called in a separate method that fires only once from thesetIntervalmethod. (you can use and a check a boolean var to make it fire only once).hope this helps