I'm retrieving list data via ajax then appending a retrieved script 'str[x]' to the page. The script is suppose to create a new 'List' object with the retrieved data.
Then i'm trying to call a method of the new object. It works if i place an alert before i call the method, but does not work when the alert is removed. At first i assumed the alert was creating a delay so all it needed was a timeout.. but adding that didn't work either.
Any ideas why i can access the object after an alert but not without it? I'm very confused..
Thanks!
Works:
Does not work:
Update: the only thing i can think of is that there is a problem creating a obj while creating an obj. Person is an object and get_lists creates several objects before during the Person object creation... but i guess that doesn't explain why adding the alert in there makes it suddenly work..
Code:
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type="text/javascript";
script.appendChild(document.createTextNode(str[x]));
head.appendChild(script);
Any ideas why i can access the object after an alert but not without it? I'm very confused..
Thanks!
Works:
Code:
function Person(lists){
this.list=lists.split(",");
get_list(lists);
alert('ok');//<----- works with this here
listobj[this.list[0]].renderList('target1');
listobj[this.list[1]].renderList('target2');
}
Code:
function Person(lists){
this.list=lists.split(",");
get_list(lists);
listobj[this.list[0]].renderList('target1');
listobj[this.list[1]].renderList('target2');
}
Comment