On 14 août, 13:11, grue <[email protected]> wrote:
> Hi,
>
> I try to perform a request from insida a native method. The JS code
> works pretty fine when I run it in a standalone html page but inside
> the gwt native method the response is empty.
> Does anyone have a clue what coud be wrong?
Any compelling reason you do not use RequestBuilder instead? (or even
com.google.gwt.xhr.client.XMLHttpRequest if you're using GWT "trunk")
> Here's the code:
>
> private native String fetchStatus(String url) /*-{
>
[...]
> xmlHttp.open('GET', url, true);
How is it that you're expecting a String to be returned while doing an
*async* request !?
> xmlHttp.onreadystatechange = function () {
> if (xmlHttp.readyState == 4) {
> alert(xmlHttp.responseText);
> return xmlHttp.responseText
> }
>
> else {
> return null;
Just in case: these "return" statements exit the closure ("function()
{ ..."), not your fetchStatus method.
I'm surprised you say it works in "pure JS", you must be doing
something slightly different there.
But it seems you're trying to do a synchronous request (which almost
everyone out there would advise you to avoid, for quite evident user
experience reasons) the asynchronous way; that's not how synchronous
XMLHttpRequest works.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" 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-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---