1

I don't know if I am doing some silly mistake here but facing this problem of firing callback functions on page init before actual event happens. Here is the code

$(document).on("pageinit",function(){
$("#discInvitePopUp").popup({
        transition: "slidedown",
        history: false,
        afterclose: function( event, ui ) {

            activeDiscInviteCloseHandler();
        },
        afteropen: function( event, ui ) {
            openDiscFrmInvite();
        }
    });

}

here are the callback functions:

function activeDiscInviteCloseHandler(){
    //some code
    //curDiscInv set
    alert("evt");
    $.post("/ajaxReq/user_action.php", {
        unsetInvite:JSON.stringify(curDiscInv)
    }, function(data){


    });

}
function openDiscFrmInvite(){
   //some code
}

here problem is that

activeDiscInviteCloseHandler()

function is called as soon as pageinit event is triggered as a result it sends post data to server which is not desirable.

Any possible solutions to avoid this.

Manish
  • 1,946
  • 2
  • 24
  • 36
  • This appears to be new functionality, and a similar problem has been noted on the jQuery mobile forums by one of the users there. Don't discount the possibility that you've come across a bug in jQuery mobile itself. – Adrian Wragg Jul 03 '13 at 21:30
  • 1
    You need to `setTimeout` to open the popup. It fires twice on pageinit due to event occurrence during pages transition and delay caused by browsers. http://stackoverflow.com/a/15738426/1771795 – Omar Jul 03 '13 at 22:13
  • can you give us the whole code, maybe the jquery mobile will trigger close on page init so the popup is not displayed ? – abdu Jul 04 '13 at 03:32

1 Answers1

-3

Instead of

$(document).on("pageinit",function()...

try

$(document).ready(function()...
Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
Kamen Stoykov
  • 1,715
  • 3
  • 17
  • 31
  • jQuery( ".selector" ).on( "pageinit", function( event ) { ... } ) We recommend binding to this event instead of DOM ready() because this will work regardless of whether the page is loaded directly or if the content is pulled into another page as part of the Ajax navigation system. – sferret Jul 03 '13 at 21:28