I was wondering why this jQuery function is not returning any value from the function. It does increase the value in Firebase and everything else works fine except returning value. Badly stuck with this for hours :(
$(function(){
$('.post').each(function(){
var $this = $(this);
var postTitle = $this.find('.title').text();
//create separate firebase reference
var postRef = new Firebase('https://bloganalyzer-view-stat.firebaseio.com/trying/'+postTitle);
var pData = getFirebaseData(postRef,'post');
$this.find('.count').empty().html(pData);
});
});
function getFirebaseData(r,bp){
var data;
r.once('value', function(snap) {
data = snap.val();
if (data == null) {data=1;}
else if(bp=='blog') {data+=10;}
else if(bp=='post') {data+=1;}
r.set(data);
});
return data;
}
and the HTML part is something like that..
<div class="post">
<span class="title">Title 1</span>
<span class="viewCount"></span>
</div>
<div class="post">
<span class="title">Title 2</span>
<span class="viewCount"></span>
</div>
Any kind of help would be appreciated.