I'm trying to update information in all tables using ajax. All the tables I want to update have the same class. So I use .each to update them all:
setInterval(function(){
$('.mtable').each(function(){
console.log("call for " + this.id);
mdebug(this.id);
})
},
15000);
The function, that beeng called uses ajax to make a request to a server and uses received information to update its content.
function mdebug(apl_ip){
table_id=apl_ip.replace(/\./g, "_");
apl_ip=apl_ip.replace(/_/g, ".");
var request=JSON.stringify({
'host' : apl_ip,
'method' : 'GET',
'command': '/wga/reverseproxy/'
});
console.log("before ajax" + table_id);
$.ajax({
type : 'POST',
url : 'isamreq.php',
data : request,
dataType : 'json',
processData : false,
contentType : 'application/json'
})
.done(function(serv_answ){
console.log("after ajax" + table_id);
});
}
To make explanation of the problem as simple as possible I left only two tables and only the code, nessesary to explanation.
Output console.log("before ajax" + table_id);
shows ids of all the tables (since this call is made for all the tables). But console.log("after ajax" + table_id);
is always the same!
Here's the console output:
So, I get
> before ajax val1
> before ajax val2
> - ajax POST
> - ajax POST
> after ajax val2 <<-- val1 IS LOST!
> after ajax val2 <<-┘
How is it possible that table_id
is overidden and how to avoid it?
I would really appriciate your help!