javascript - Firebase: Get userdata obj and bring back the user profile without page refresh? -


it's been 2 days i'm trying achieve need refresh page if want user profile db. there way without page refresh? need use sort of jquery ajax achieve it? possible?

here 2 method, they're working need page refresh before bring user profile.

 function authdatacallback(authdata) {   if (authdata) {     var fb = new firebase('https://blistering-torch-8000.firebaseio.com/users/public/');     fb.child(authdata.uid).on('value', function(data) {       var mydata = data.val();       var datestring = mydata.date.split(' ').slice(0, 4).join(' ');       $('.profile').append('<li>username: ' + mydata.username + '</li>');       $('.profile').append('<li>joined: ' + datestring + '</li>');     });     var fb = new firebase('https://blistering-torch-8000.firebaseio.com/users/private/');     fb.child(authdata.uid).on('value', function(data) {       var mydata = data.val();       $('.profile').append('<li>email: ' + mydata.email + '</li>');     });   } else {     console.log('profile: no data, no 1 logged in');   } } fb.onauth(authdatacallback); 

or

var fb = new firebase('https://blistering-torch-8000.firebaseio.com/'); var getauth = fb.getauth();  function getprofile(authdata) {   if (authdata) {     var fb = new firebase('https://blistering-torch-8000.firebaseio.com/users/public/');     fb.child(authdata.uid).on('value', function(data) {       var mydata = data.val();       var datestring = mydata.date.split(' ').slice(0, 4).join(' ');       $('.profile').append('<li>username: ' + mydata.username + '</li>');       $('.profile').append('<li>joined: ' + datestring + '</li>');     });     var fb = new firebase('https://blistering-torch-8000.firebaseio.com/users/private/');     fb.child(authdata.uid).on('value', function(data) {       var mydata = data.val();       $('.profile').append('<li>email: ' + mydata.email + '</li>');     });   } else {     console.log('profile: no data, no 1 logged in');   } } getprofile(getauth); 

db rules:

{   "rules":    {     "users":      {       "public":        {          // allow me list users name         ".read": true ,         ".write": true       },        "private":        {         "$uid":          {           // readable owner           ".read": "auth.uid === $uid",           ".write": true         }       }     }      } } 

both onauth , getauth return null when not authenticated. fix login/function call sequence.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -