From: bruce on
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
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
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