【问题标题】:Uncaught Syntax errors on htmlhtml 上未捕获的语法错误
【发布时间】:2020-07-02 15:13:02
【问题描述】:

我正在尝试构建一个集成了 Google 登录身份验证的网页。我有我的 index.html 和我的 app.js 文件,只要登录成功,它就会被调用。由于我不知道的原因,我不断收到此未捕获的语法错误,任何人都可以帮助我。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
    <meta name="description" content="Front-End for Bootstrap Tutorial" />
    <meta name="author" content="CSE 216 Student Name Goes Here" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />


    <title>Super Deuper Epic App</title>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
    </script>
    <script src="https://apis.google.com/js/client:platform.js?onload=start" async defer>
    </script>
    <script>
        function start() {
      gapi.load('auth2', function() {
        auth2 = gapi.auth2.init({
          client_id: '937584788497-tpt2bujc0dbi8g3a8808b1ssc83c1657.apps.googleusercontent.com',
          fetch_basic_profile: false,
               scope: 'profile'
        });
      });
    }
      </script>
    <script src="jquery.min.js"></script>
    <script src="handlebars.min.js"></script>
    <script src="bootstrap.min.js"></script>
    <script src="templates.js"></script>
    <!-- <script src="app.js"></script> -->

    <link href="https://fonts.googleapis.com/css?family=Fresca" rel="stylesheet">
    <link rel="stylesheet" href="app.css" />
    <link href="bootstrap.min.css" rel="stylesheet">

</head>

<body>
        
        <div id="my-signin2"></div>
        <button id="sign-out" onclick="signOut()">Sign Out</button>
        <script>
          function renderButton() {
          gapi.signin2.render('my-signin2', {
            'scope': 'profile email',
            'width': 240,
            'height': 40,
            'longtitle': true,
            'theme': 'dark',
          });
            $('#sign-out').attr('style', 'display: none');
          }
          $('#my-signin2').click(function() {
            // signInCallback defined in step 6.
            auth2.grantOfflineAccess().then(signInCallback);
          });
          
        </script>
        <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
        <script>
          var script = document.createElement('script');
          script.src = 'app.js';
          function signOut(){
            var auth2 = gapi.auth2.getAuthInstance();
            auth2.signOut().then(function(){
              $('#my-signin2').attr('style', 'display: block');
              $('#sign-out').attr('style', 'display: none');
              history.go(-1);
              console.log('User logged out');
            })
          }
                function signInCallback(authResult) {
                  if (authResult['code']) {
                    // Hide the sign-in button now that the user is authorized, for example:
                    $('#my-signin2').attr('style', 'display: none');
                    
                    // Send the code to the server
                    $.ajax({
                      type: 'POST',
                      url: 'https://super-deuper-epic-app.herokuapp.com/',
                      // Always include an `X-Requested-With` header in every AJAX request,
                      // to protect against CSRF attacks.
                      headers: {
                        'X-Requested-With': 'XMLHttpRequest'
                      },
                      contentType: 'application/octet-stream; charset=utf-8',
                      success: function(result) {
                        console.log("Result is:" + result);
                        document.body.appendChild(script);
                        $('#sign-out').attr('style', 'display: block');
                          
                        // Handle or verify the server response.
                      },
                      processData: false,
                      data: authResult['code']
                    });
                  } else {
                      console.log("Error");
                      
                    // There was an error.
                  }
                }
                </script>
            

</body>

</html>

最奇怪的部分是它曾经可以工作,就像完全集成了登录和注销等所有内容,但是第二天,当我在不更改代码的情况下运行它时,出现了以下错误:

(index):19 Uncaught SyntaxError: Unexpected identifier - 函数 start() {
(index):46 Uncaught SyntaxError: missing ) 在参数列表之后
- $('#sign-out').attr('style', 'display: none');
(index):49 Uncaught SyntaxError: Unexpected identifier
- 函数 renderButton() {
gapi.signin2.render('my-signin2', {
'范围':'个人资料电子邮件',
“宽度”:240,
“身高”:40,
'longtitle':是的,
“主题”:“黑暗”,
});
}
(index):66 Uncaught SyntaxError: Unexpected identifier - var script = document.createElement('script');

【问题讨论】:

    标签: javascript jquery html


    【解决方案1】:

    我认为相同的代码对我有用 我已经修复了一些语法问题

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
        <meta name="description" content="Front-End for Bootstrap Tutorial" />
        <meta name="author" content="CSE 216 Student Name Goes Here" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>Super Deuper Epic App</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script src="https://apis.google.com/js/client:platform.js?onload=start" async defer></script>
        <script src="jquery.min.js"></script>
        <script src="handlebars.min.js"></script>
        <script src="bootstrap.min.js"></script>
        <script src="templates.js"></script>
        <!-- <script src="app.js"></script> -->
        <link href="https://fonts.googleapis.com/css?family=Fresca" rel="stylesheet">
        <link rel="stylesheet" href="app.css" />
        <link href="bootstrap.min.css" rel="stylesheet">
    </head>
    
    <body>
        <div id="my-signin2"></div>
        <button id="sign-out" onclick="signOut()">Sign Out</button>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script>
            $('#sign-out').attr('style', 'display: none');
        </script>
        <script>
            function start() {
                gapi.load("auth2", function () {
                    auth2 = gapi.auth2.init({
                        client_id: '937584788497-tpt2bujc0dbi8g3a8808b1ssc83c1657.apps.googleusercontent.com',
                        fetch_basic_profile: false,
                        scope: 'profile'
                    });
                });
            }
    
            function renderButton() {
                gapi.signin2.render('my-signin2', {
                    'scope': 'profile email',
                    'width': 240,
                    'height': 40,
                    'longtitle': true,
                    'theme': 'dark',
                });
            }
            $('#my-signin2').click(function () {
                auth2.grantOfflineAccess().then(signInCallback);
            });
        </script>
        <script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
        <script></script>
    </body>
    </html>

    【讨论】:

    • 你能把你的代码和截图分享给我,以便我检查
    • 我在我发布的问题上编辑了整个代码,现在你可以检查它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 2016-10-18
    • 2019-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多