小编Ale*_*haw的帖子

Google登录-未定义googleUser

我一直在关注Google登录教程,以创建一个登录系统,而此时我有一个登录按钮,该按钮会加载用于选择登录的小部件。单击后,将加载以下功能:

function onSignIn(googleUser) {
  var profile = googleUser.getBasicProfile();
  console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
  console.log('Name: ' + profile.getName());
  console.log('Image URL: ' + profile.getImageUrl());
  console.log('Email: ' + profile.getEmail());
}
Run Code Online (Sandbox Code Playgroud)

但是,一旦我选择了帐户并登录,就什么也没有发生。在开发人员控制台中,当我输入“ googleUser”时,它只会显示:

未捕获的ReferenceError:未定义googleUser

这是我所有的代码:

function onSignIn(googleUser) {
  var profile = googleUser.getBasicProfile();
  console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
  console.log('Name: ' + profile.getName());
  console.log('Image URL: ' + profile.getImageUrl());
  console.log('Email: ' + profile.getEmail());
}
Run Code Online (Sandbox Code Playgroud)

请注意,运行代码段将不起作用

html javascript google-signin google-identity

5
推荐指数
2
解决办法
3262
查看次数

将JSON对象的一部分存储在javascript变量中

我想将一个主JSON对象的一部分存储在一个变量中,以便我可以遍历它(例如,存储'cards',这样我就可以遍历Govenors,Courses和Teachers来获得'title'和'href '在用它们创建元素之前).目前我在做:

var content = $.getJSON("website-contents.json");
var place = content["cards"];
Run Code Online (Sandbox Code Playgroud)

当我在Chrome开发工具中调用内容变量时,它会返回我的主对象,但是当我调用'place'变量时,它只返回undefined.我也试过var place = content.cards,var place = content[0]但似乎没有任何工作.这是我的JSON(道歉长度)

{
  "accordian" : {
    "faqs" : {
      "head" : {
        "answer" : "Simon Firth",
        "question" : "Whos the head?"
      },
      "location" : {
        "answer" : "Wylye Bulding, Wiltshire College",
        "question" : "Where are we based?"
      }
    }
  },
  "article" : {
    "new-site" : {
      "Title" : "Launch of new website!",
      "author" : "Alex Shaw",
      "content" : "We now have …
Run Code Online (Sandbox Code Playgroud)

javascript jquery json

2
推荐指数
1
解决办法
152
查看次数

通过Javascript从PHP保存到服务器端文件

我试图使用PHP将json字符串从javascript文件保存到服务器上的本地文件,但是,我的json文件根本没有被修改.这是我的Javascript:

function saveToFile(data){
  jsonString = JSON.stringify(data);
  $.ajax({
    url: 'php/save.php',
    data : jsonString,
    type: 'POST'
  });
}
Run Code Online (Sandbox Code Playgroud)

请注意,jsonString是一个有效的变量,我可以将其正确记录到控制台中.

这是我的PHP:

<?php
  $data = $_POST['jsonString'];
  $f = fopen("../website-contents.json", "w") or die("fopen failed");
  fwrite($f, $data) or die("fwrite failed");
  fclose($f);
?>
Run Code Online (Sandbox Code Playgroud)

请注意,即使尝试将"Hello World"保存到"test.txt"的测试也不起作用或通过错误.

最后,这是我的文件夹结构: 在此输入图像描述

html javascript php

1
推荐指数
1
解决办法
4131
查看次数

标签 统计

javascript ×3

html ×2

google-identity ×1

google-signin ×1

jquery ×1

json ×1

php ×1