有时Google图表库无法加载。抛出以下错误:
Uncaught TypeError: Cannot read property 'then' of undefined
at Object.google.G.K.T.Ak (loader.js:225)
at Object.google.G.load (loader.js:226)
这是我的页面代码:
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
</head>
这是我的Javascript:
$( function() {
// wait for page to load
window.addEventListener('load', loadGoogle, false);
function loadGoogle() {
// define callback in load statement
google.charts.load('current', {'packages':['corechart'], 'callback': loadApp});
}
function loadApp() {
// do some amazing stuff
}
} );
有些日子它有效,有些日子它没有。
我还尝试将所有内容放在我的页面中,如下所示:
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', { packages: [ 'corechart', 'table', 'bar', 'controls' ]});
google.charts.setOnLoadCallback( function(e) { alert('callback');});
</script>
当我这样做时,我得到一组不同的错误:
Uncaught TypeError: Promise.resolve is not a function
at loader.js:239
at loader.js:243
Uncaught (in promise) Error: Bad version: current
at loader.js:224
at <anonymous>