【问题标题】:XMLHttpRequest posts not being pushXMLHttpRequest 帖子没有被推送
【发布时间】:2019-12-01 23:57:58
【问题描述】:

我正在尝试在客户端使用 Google 平台库和在后端使用 google-auth-library 对用户进行 o 身份验证。使用以下代码,因为我正在关注official tutorial

<meta name="google-signin-client_id"
  content="myuserid.apps.googleusercontent.com">
<meta name="google-signin-scope" content="profile email">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
  function onSignIn(googleUser) {
    var profile = googleUser.getBasicProfile();
    var id_token = googleUser.getAuthResponse().id_token;
    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'http://mysubdomain.openshiftapps.com/oauth/google/redirect');
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.onload = function() {
      console.log('Signed in as: ' + xhr.responseText);
    };
    xhr.send('idtoken=' + id_token);
  }
</script>

我没有看到客户端发出任何发布请求。

使用 Chrome 或 Internet Explorer 调试工具,只显示加载资源的请求,platform.js 其中。

ps:myuserid 和 mysubdomain 被它们的值替换。

【问题讨论】:

  • 控制台没有错误?
  • 你有原因,它显示类似:“cookies are not enabled in current environment.”错误:“idpiframe_initialization_failed”但我一开始没有注意。

标签: javascript http request xmlhttprequest


【解决方案1】:

这是一个 cookie 授权问题。我授权了 google.com、accounts.google.com 和我的网络应用程序的域名。现在一切都恢复正常了。

【讨论】:

    猜你喜欢
    • 2016-05-14
    • 2012-04-30
    • 2020-02-22
    • 2015-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-10
    相关资源
    最近更新 更多