because that is what the code is doing in the lines:
if (!window[callback + "done"]) {
[EMAIL PROTECTED]::handleJsonResponse(Ljava/
lang/String;)(null);
which seems to be called when there is no response yet received from
the server returning the JSON server. There is an issue with this
type of design - for some reason it it polling for an asynchronous
result and when not found returns a null, and schedules for another
look later, it also tries to handle that asynchronous result when it
is returned. So, you either have to cope with getting a null back
several times until a real answer, or remove the scheduling (it is not
needed in the normal case, maybe the author of the web site the code
comes from needed it for some other reason...)
You should probably look at the code written by Dan Morill from the
GWT team for an approach that is proper for the general case:
http://code.google.com/support/bin/answer.py?answer=65632&topic=11368
//Adam
On 21 Okt, 16:24, Slim LAU <[EMAIL PROTECTED]> wrote:
> public native static void getJson(int requestId, String url,
> MyApplication handler) /*-{
> var callback = "callback" + requestId;
>
> var script = document.createElement("script");
> script.setAttribute("src", url+callback);
> script.setAttribute("type", "text/javascript");
>
> window[callback] = function(jsonObj) {
>
> [EMAIL PROTECTED]::handleJsonResponse(Ljava/
> lang/String;)(jsonObj.toJSONString());
> window[callback + "done"] = true;
>
> }
>
> // JSON download has 1-second timeout
> setTimeout(function() {
> if (!window[callback + "done"]) {
>
> [EMAIL PROTECTED]::handleJsonResponse(Ljava/
> lang/String;)(null);
> }
>
> // cleanup
> document.body.removeChild(script);
> delete window[callback];
> delete window[callback + "done"];
>
> }, 1000);
>
> document.body.appendChild(script);
>
> }-*/;
>
> public void handleJsonResponse(String jso) {
> Window.alert(jso);
>
> }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---