why "google is not defined " when i load google js api
i follow the api step by step,but can't load successful..
this is my code:
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body >
<script type="text/javascript" src="http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22gdata%22%2C%22version%22%3A%222.x%22%2C%5B%22callback%22%3A%22onLoad%22%2C%22packages%22%3A%5B%22maps%22%5D%5D%7D%5D%7D"></script>
<script type="text/javascript">
var service = new google.gdata.maps.MapsService('docs-example');
</script>
</body>
</html>
the error is :google is not defined
why ??
upedted
i change my code,and it worked,but it fire the errorHandler and then alert "error!!!":
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body >
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the latest version of the Google Data JavaScript Client
google.load('gdata', '2.x', {packages: ['maps']});
function开发者_C百科 onGoogleDataLoad() {
// Put your code here
}
// Call function once the client has loaded
google.setOnLoadCallback(onGoogleDataLoad);
</script>
<script type="text/javascript">
var service = new google.gdata.maps.MapsService('docs-example');
listMaps()
function listMaps() {
var list = document.createElement('ul');
var mapFeedUrl = 'http://maps.google.com/maps/feeds/maps/default/owned';
service.getMapFeed(mapFeedUrl, function(feedRoot) {
var feed = feedRoot.feed;
var entries = feed.getEntries();
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var mapTitle = entry.getTitle().getText();
var listItem = document.createElement('li');
var listText = document.createTextNode(mapTitle);
listItem.appendChild(listText);
list.appendChild(listItem);
}
document.body.appendChild(list);
}, errorHandler)
}
function errorHandler(){
alert('error!!!')
}
</script>
</body>
</html>
why ?
thanks
you should put any call to the google stuff inside the onGoogleDataLoad()
function to make sure it is not launched before the APIs have finished loading.
function onGoogleDataLoad() {
var service = new google.gdata.maps.MapsService('docs-example');
listMaps()
}
If you check the JS URL with your browser, you get the following result:
var error = new Error("Invalid autoload.");
error.toString = function() { return this.message; }
throw error;
Meaning, there's something wrong with your URL.
精彩评论