Possible Duplicate:
Javascript infamous Loop problem?
I am having troubles trying to access a variable inside a $.post
function.
The value of the variable a
inside the function is always the same: 7. But outside it, it increases as I want.
Why is this happening? How can I do a loop for a $.post
function?
for(var a=0; a<7; a++){
console.log(a); /* increasing value */
$.post("http://"+ document.domain + "/posts/user/xxxxx",
function(departments){
console.log(a); /*value of 7*/
});
}
Thanks.