On Oct 25, 7:17 pm, "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.
>
> -MikeThe reason for using "onreadystatechange" is to detect a failure. Without it, the browser will wait forever with the callback function never being called. It was an answer to his question about a non- existent JS file. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
