简体   繁体   English

Google Firebase uid网站

[英]Google Firebase uid web

I'm trying to get the google ID (using the function getGoogleID()) to build a variable that has a URL parameter, it gets sent to PHP. 我正在尝试获取google ID(使用getGoogleID()函数)来构建具有URL参数的变量,并将其发送到PHP。 I have tried it with hardcoding the correct string in, but can't get it so it's unique to the logged in user. 我尝试用硬编码正确的字符串来尝试它,但是无法获得它,因此它对于登录用户是唯一的。 Its being used with DataTables. 它与DataTables一起使用。

//Code to call Google to get uid
function getGoogleID() {
var user = firebase.auth().currentUser;

if (user != null) {
    return user.uid;
    };
};

//Code to Build Datatable
function buildTable(uid) {

        $('#assessmentTable').DataTable({
            "processing": true,
            "paging":false,
            "ajax": "connect/fm/customerAssessmentsList.php?id=" + uid,
            "columns": [
                {"data": "fieldData.Remote Tests::Test Date"},
                {"data": "fieldData.Remote Test Calculations::Test Name"},
                {"data": "fieldData.Result 1"},
                {"data": "fieldData.Result 2"},
                {"data": "fieldData.Result 3"},
                {"data": "fieldData.Result 4"}
            ],
            order: [[1, 'asc'],[0,'desc']],
            rowGroup: {
                dataSrc: 'fieldData.Remote Test Calculations::Test Name',
                className: 'bg-success text-white'
            },
            "responsive":true
        });
    }
//Document Ready
$(document).ready(function() {
    var uid = getGoogleID();
    buildTable(uid);
});

What am I missing? 我想念什么? I can call getGoogleID() in the console and get a proper response. 我可以在控制台中调用getGoogleID()并获得适当的响应。 It's almost like it calls the buildTable() before getGoogleID() finishes and returns the uid. 就像在getGoogleID()完成并返回uid之前调用buildTable()一样。

You can debug in a browser and see what it is calling first. 您可以在浏览器中进行调试,然后先查看它在调用什么。 Anyway, you can use a if or call the uid in the function buldTable directly. 无论如何,您可以使用if或直接在函数buldTable中调用uid。 It can also be a scope problem. 这也可能是范围问题。

//Document Ready //准备好文件

$(document).ready(function() {

    function getGoogleID() {
        var user = firebase.auth().currentUser;

        if (user != null) {
           return user.uid;
        };
     };
    var uid = getGoogleID();

    //define buildTable here

    //Then call it
    buildTable(uid);
    if (uid !=  null || typeof(uid) != 'undefined' || uid != ""){
       buildTable(uid);
     } else {
      //do something
     }

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM