“无法读取未定义的属性'load'" [英] "Cannot read property 'load' of undefined"

查看:80
本文介绍了“无法读取未定义的属性'load'"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循文档进行集成使用Google登录,尽管我在控制台中遇到此错误:

I'm attempting to follow this documentation to integrate with Google sign in, though I'm running into this error in console:

未捕获的TypeError:无法读取未定义的属性"load"
        at script.js:1

script.js :

window.gapi.load('auth2', function() {
    console.log('Loaded!');
});

大约一半时间出现错误,并且在Chrome中检查了网络面板,只有在以下资源未未加载时,该错误才会发生:

I get the error about half of the time, and inspecting the network panel in Chrome, it only happens when the following resource is not loaded:

https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.en.d2dliHDvPwE.O/m=auth2/exm=signin2/rt=j/sv = 1/d = 1/ed = 1/am = AQ/rs = AGLTcCNGAKhVlpzmTUpjFgzBXLpLM_oEFg/cb = gapi.loaded_1

如何消除此错误?

如果有用,这是我的 index.html :

<!DOCTYPE html>
<html>
    <head>
        <title>Google Sign In Test</title>
        <meta name="google-signin-client_id" content="*****.apps.googleusercontent.com">
        <script src="https://apis.google.com/js/platform.js" async defer></script>
        <script src="script.js" async defer></script>
    </head>
    <body>
        <div class="g-signin2" data-onsuccess="onSignIn"></div>
    </body>
</html>

推荐答案

尝试将onload事件添加到脚本标签.因此,将您的脚本标签更改为

Try adding an onload event to the script tag. So change your script tag to

<script src="https://apis.google.com/js/platform.js?onload=myFunc" async defer></script>

然后将您的代码包装在回调函数中.

Then wrap your code in the callback function.

这篇关于“无法读取未定义的属性'load'"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆