I have two examples. Please tell me why my variable help
is not working as intended in this examples. I checked it is getting into the loop.
Result: undefined
function autopop(){
var help;
$.ajax({
type : "POST",
url : "/cgi-bin/my.pl",
data : "action=autopop",
dataType : "json",
success : function(data) {
for (var i = 0; i < data.length; i++) {
help = "test";
}
}
);
$("#id").append(help);
}
Result: test
function autopop() {
var help = "test";
$.ajax({
type : "POST",
url : "/cgi-bin/my.pl",
data : "action=autopop",
dataType : "json",
success : function(data) {
for (var i = 0; i < data.length; i++) {
help = "blub";
}
}
);
$("#id").append(help);
}
Please tell my why I can't access my var from within this ajax/loop combination and how I can change this fact.