[Javascript] return value from "ajax"/ function

Brian L. Matthews blmatthews at gmail.com
Sat Dec 9 13:10:57 CST 2006


>Well, yes you can; AJAX's 'A'synchronicity is optional. Change your
>function (completely off the top of my head, untested, no error
>checking, etc.) to:
>
>function requestFile(url) {
>   httpRequest.open('get', url, false);
>   httpRequest.send(null);  // synchronous; returns when response is complete
>   return httpRequest.responseText;
>}

Ah yes, I totally forgot about synchronous requests. However, I'd 
argue that's a good thing. :-) Synchronous requests can easily make 
for a bad user experience, and using asynchronous requests isn't that 
much harder.

Brian



More information about the Javascript mailing list