pagebeforechange event getting called multiple times

pagebeforechange event getting called multiple times

Hi,

I'm using code under 

$(document).on('pagebeforechange', function (e, data) {
//my code
})

This method is getting called multiples time when i visit the page again.
Also  data.toPage[0] contains string some times and sometimes object.
My code is failing as i am considering it object all the times.

Please help me.