This code load the content of the php file with the parameter: online and name and print them dynamic every 0.2s, the whole code works, but it says that ” stats ” is not defined in internet explore, i dont know why. Help me out guys
function updateStats(stat)
{
var stat = ["online","name"];
var stats = "";
if (stat==undefined)
{
document.write("is undefined");
}
var url = "online.php";
$.each(stat, function(i, key){
$.post(url, {stats: key}, function(data) {
$("#" + key).html(data);
});
});
}
setInterval('updateStats("updateStats")', 200); // 200 milliseconds = 0.2 seconds
this is the updated code, but still says that stats not defined
function updateStats(stat)
{
var stat = ["online","money"];
if (typeof stat == "undefined")
{
document.write("stat is undefined");
}
var url = "online.php";
$.each(stat, function(i, key){
$.post(url, {stats: key}, function(data) { // stats to stat
$("#" + key).html(data);
});
});
}
setInterval(function(){
updateStats("updateStats");
}, 1000);
if (typeof stats == "undefined")
{
document.write("stats is undefined");
}
Change:
To:
Also to check if something is
undefined, instead of:Use:
Also as pointed out by @Felix Kling, you are passing
statvariable via function:And also creating it later on inside that function:
which is weird, you should modify your code to account for that.