
Signature
Martin Honnen
http://JavaScript.FAQTs.com/
> The onreadystatechange handler is a function of its own that is called
> but XMLHttpRequest object when the readyState changes, the phj_func call
> is already finished when the handler is called so obviously you can't
> return any value in phj_func that stems from the onreadystatechange
> event handler.
> You need to call another function and pass the responseText text e.g.
Cheers. Is there a way though to have the data returned to the function
called. Ie:
str = phj_func(url)?
Something like:
function phj_func(file,func,args) {
var r = false;
function got_data(str_data) {
r = str_data;
}
xmlhttp.open("GET", url)
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
got_data(xmlhttp.responseText);
}
}
xmlhttp.send(null);
return (r);
}
though... that doesn't work.
Martin Honnen - 30 Dec 2004 17:07 GMT
>> The onreadystatechange handler is a function of its own that is called
>> but XMLHttpRequest object when the readyState changes, the phj_func
[quoted text clipped - 5 lines]
> Is there a way though to have the data returned to the function
> called.
No, as said the function call to phj_func simply sets up an
onreadystatechange event handler, then calls the send method and exits,
it is already finished before the onreadystatechange event handler is
called for the first time.
There is some sort of event based programming in PHP too, for instance
if you look at the XML parser functions using Expat, there you set up
event handlers like the element_handler and then those are called when
elements are parsed.

Signature
Martin Honnen
http://JavaScript.FAQTs.com/
Jason Morehouse - 30 Dec 2004 17:11 GMT
> There is some sort of event based programming in PHP too, for instance
> if you look at the XML parser functions using Expat, there you set up
> event handlers like the element_handler and then those are called when
> elements are parsed.
Ah, of course. Thank you!