gpt4 book ai didi

javascript - html 上未捕获的语法错误

转载 作者:行者123 更新时间:2023-12-01 05:12:00 25 4
gpt4 key购买 nike

我试图构建一个集成了 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 - function start() {
(index):46 Uncaught SyntaxError: missing ) after argument list
- $('#sign-out').attr('style', 'display: none');
(index):49 Uncaught SyntaxError: Unexpected identifier
- function renderButton() {
gapi.signin2.render('my-signin2', {
'scope': 'profile email',
'width': 240,
'height': 40,
'longtitle': true,
'theme': 'dark',
});
}
(index):66 Uncaught SyntaxError: Unexpected identifier -  var script = document.createElement('script');

最佳答案

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

enter image description here

<!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>

关于javascript - html 上未捕获的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60791838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com