Prev: Code works with IE7, FF3.5 but not IE8 and Why?
Next: FAQ Topic - How do I make a 10 second delay? (2010-04-24)
From: bruce on 21 Apr 2010 13:01 I want to get access to some server data to be used by JavaScript. I am using AJAX and can get the data using a client ID (<div id=datahere></div). This works great. But, I want to use data that ends up at "datahere" in a JavaScript function using obj.innerHTML = xmlhttp.responseText; Also, if I place a global of var MyData; and set it to MyData = "TEMP"; Then modify the ajax routine to have MyData = xmlhttp.responseText; alert(MyData); The alert does display my retrieved item but I still have "TEMP" in MyData when I try to access it with my other function. I know it's the 'asynchronous nature of AJAX that's giving me the problem. So, what do I need to do. I tried <input type=hidden id=valueId value= ""> This didn't seem to work either. Again, how to I get at the data returned from the server by AJAX in another JavaScript function? Thanks for the help...
From: Scott Sauyet on 21 Apr 2010 13:12 bruce wrote: > Again, how to I get at the data returned from the server by AJAX in > another JavaScript function? You'll need to put the code that depends upon the changed value inside a function that either serves as the callback handler for the AJAX call or is called by that handler. Asynchronous communication requires a somewhat different programming style. // ... xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { handleChangedData(xmlhttp.responseText); } } -- Scott
From: bruce on 21 Apr 2010 13:16
On Apr 21, 1:12 pm, Scott Sauyet <scott.sau...(a)gmail.com> wrote: > bruce wrote: > > Again, how to I get at the data returned from the server by AJAX in > > another JavaScript function? > > You'll need to put the code that depends upon the changed value inside > a function that either serves as the callback handler for the AJAX > call or is called by that handler. Asynchronous communication > requires a somewhat different programming style. > > // ... > xmlhttp.onreadystatechange=function() { > if (xmlhttp.readyState==4 && xmlhttp.status==200) { > handleChangedData(xmlhttp.responseText); > } > } > > -- > Scott Thanks for the response. Your suggestion changes my design (which is okay) so I'll need to modify stuff and try it out. To quote Arnold, "I'll be back." Thanks again.. Bruce |