Michael, I partly agree with you.
You are right that you don't need a timer or worry about event
handling when using a callback function. However that's only going to
work, if nothing goes wrong on the server end and the JSON is
delivered correctly and in time.
The reason I was using a timer was because in some application it
might be critical to dectect if the data doesn't arrive correctly or
in time. Just think about an interval server error (error 500) or the
site being down at all. In this case your callback function is never
called and you just wait forever. Not so good if you depend on it.
I see two possible solution:
a) a timer and
b) event handling with onreadystatechange/onload/onerror.
bratcliff said:
> It can be done with event handlers. For Internet Explorer, use
> "onreadystatechange". For Firefox & others, use "onload" / "onerror".
What I am really looking for is a solution that will work for all
browsers for which GBrowserIsCompatible() is true. Does anyone happen
to know if I can rely on using onreadystatechange for IE and onload/
onerror for FF and *all* others?
Jürgen
On 25 Okt., 21:17, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> The "{lat=xxx, lon=xxx}" must a typo? That is neither JSON nor JavaScript.
>
> Proper JSON would look like this (the whitespace is optional):
>
> { "lat": 40.0, "lng": -120.0 }
>
> BTW, the quotes on the property names are required for correct JSON format,
> although they don't matter if you're just generating executable JavaScript.
>
> By adding the variable assignment, you've changed the response from JSON to
> executable JavaScript code.
>
> However, that's not a complete solution. How do you know when your script
> has loaded? You don't get notified that a variable has been assigned into.
>
> That's why JSONP uses a callback, not a variable assignment. If the server
> response is:
>
> mycallback({ "lat": 40.0, "lng": -120.0 })
>
> Then you *know* when it's loaded, because your "mycallback" function is
> called at that time.
>
> Now you don't have to use a timer (BAD idea!). You don't have to worry about
> readystatechange. You don't have to do any of that. You simply have a
> function in your JavaScript code that *automatically* gets called at exactly
> the right moment.
>
> As I mentioned in my other message, the customary way to do this is to
> provide a callback function name in the URL, such as:
>
> http://example.com/myjsonservice?foo=bar&abc=xyz&callback=callme
>
> Then the server would generate:
>
> callme({ "lat": 40.0, "lng": -120.0 })
>
> This places control of the actual function name in the client code.
>
> You don't *have* to do that; you can have a hard coded callback function
> name if you want. But the conventional JSONP approach used by many sites
> lets the client specify the callback name. Most JavaScript libraries such as
> jQuery now have built-in support for JSONP with a callback - it's really the
> way to go.
>
> -Mike
>
>
>
> > From: Neil.Young
>
> > Exactly. The "straight" JSON, delivered until now by my
> > server, didn't work the very first attempt. Reason: I was
> > missing the assignment statement, so the plain JSON object
> > "{lat=xxx, lon=xxx}" had to be delivered padded with a
> > variable assignment, e.g. "data = {lat=xxx, lon=xxx}" by the server.
>
> > But Micheal: Why this?
>
> > JSON is not executable JavaScript and cannot be used
> > cross-domain without a proxy.
>
> > I think, "cross-domaining" is of course possible, but it is
> > probably hard to deal with the results? The server side is
> > called in any case...
> > Or do I catch that wrong? For me XMLHttpRequest is not cross
> > domain and cannot be used w/o proxy, that's for sure.- Zitierten Text
> > ausblenden -
>
> - Zitierten Text anzeigen -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API" 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-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---