Google Ajax API unifies Google's own JS library and current mainstream JS library, including YUI and Ext. JS, Dojo, jQuery, SWFObject, and different versions, as well as compression and non-compression, provide developers with dynamic and automatic loading features, opening up a new situation.
Load
On the Google website, it is prompted that the API key is required for use, but it is not actually required. Google has already opened all of them. The following simple code can be used to reference Google Ajax APIs:
1. <script type = "text/javascript" src = "https://www.google.com/jsapi"> </script>
GoogleLoader
On the whole, the key to Google Ajax API is Loader. Each JS library exists as a module and is dynamically loaded. The rule is as follows:
1. google. load (moduleName, moduleVersion, optionalSettings)
Where: moduleName: Module name;
ModuleVersion: module version;
OptionalSettings: Optional. The attributes include: callback:
Callback after loading is completed;
Language: The UI language of the loaded module;
Nocss: bool type. whether to add CSS related to the module. The default value is false;
Packages: specify other related packages involved in the use of the module;
Base_domain: Specifies the top-level domain of a module. For example, if the GoogleMap module maps is loaded and the specified domain is ditu.google.cn, the map API of the Chinese version is automatically loaded;
Other_params: Other parameters are completed using the <script> tag. For details, refer to the Google website.
Currently, JS libraries that do not support dynamic loading include: Friend Connect Earth gData Orkut. They do not support callback.
Sample loading Module
1. <script type = "text/javascript">
2. google. load ("search", "1 ");
3. google. load ("jquery", "1.4.2 ");
4. google. load ("jqueryui", "1.7.2 ");
5. </script>
Callback
1. function mapsLoaded (){
2. var map = new google. maps. Map2 (document. getElementById ("map "));
3. map. setCenter (new google. maps. LatLng (37.4419,-122.1419), 13 );
4 .}
5.
6. function loadMaps (){
7. google. load ("maps", "2", {"callback": mapsLoaded });
8 .}
This article is from the blog "Excellent by focus-Peng Jinhua"