Hi Benjamin, thanks for the help. I actually had something like that before but I think I declare a global variable as the XMLHttpRequest, causing multiple calls of the function to collide.
Sebastian On Jan 15, 7:26 pm, "Benjamin [API Guru]" <[email protected]> wrote: > Hi Sebastian, > > You can attach a generic function to onreadystatechange which sets the > responseStream to a img object you pass by reference: > > function loadImage(url, img) { > var req = new XMLHttpRequest(); > req.onreadystatechange = function() { > if (req.readyState == 4) { > if (req.status == 200) { > img.src = req.responseStream; > } > } > } > req.open('GET', url, true); > req.send(); > > } > > Best regards, > Benjamin > > On Jan 15, 12:03 am, Sebastian <[email protected]> wrote: > > > Hi, > > > I am stuck on some ugly code I am trying to optimize. The problem is, > > that I cannot reference to a variable without using eval (which is > > unsafe and slow). I tried to replace it with the square bracket > > notation (while removing the quotes in the function call), but cannot > > get it to work. Any help is much appreciated! > > Here is the code: > > > var logoload; > > var logourl="http://foo.bar"; > > > function viewonopen() > > { > > XHR("logoload", "logourl", "loadlogo");} > > > function XHR(name, url, readystatefunction) { > > mycode = name +"=null;"; > > mycode += name +"=new XMLHttpRequest();"; > > mycode += name +".onreadystatechange="+readystatefunction+";"; > > mycode += name +".open(\"GET\","+url+",true);"; > > mycode += name +".send(null);"; > > eval(mycode);} > > > function loadlogo() { > > if(logoload.readyState!=4) return; // NOT READY > > if(logoload.status!=200) return; // FAILED > > img1.src = logoload.responseStream; > > img1.visible = true; > > logoload = null; > > > } > > > Thanks, > > Sebastian --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Desktop Developer Group" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Desktop-Developer?hl=en -~----------~----~----~----~------~----~------~--~---
