jquery mobile取消pagebeforeshow事件

时间:2012-03-16 17:35:06

标签: ajax jquery jquery-mobile

在jquery mobile中,有没有办法取消在pagebeforeshow事件中显示的页面?我在pagebeforeshow上有一些权限检查代码,如果不符合许可,我想引导用户登录页面。

$("secretpage").live("pagebeforeshow", function () {
  if (permissionNotMet()) {
    stopShowingPage()         //    <---- how?
    $.mobile.changePage("#signin")
  }
})

1 个答案:

答案 0 :(得分:0)

这不是您要求的,但您可以重新编写代码流程,以便让自己更轻松。

自行处理您的登录表单提交,然后根据服务器响应将用户定向到正确的页面:

$(document).delegate('#login', 'pageinit', function () {
    function loginSuccess (serverResponse) {

        $.mobile.hidePageLoadingMsg();

        //here you check the `serverResponse` and direct the user where they need to go
    }
    function loginError (jqXHR, textStatus, errorThrown) {
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
    }
    $(this).find('form').bind('submit', function () {

        $.mobile.showPageLoadingMsg();

        $.ajax({ url : '<url>', data : $(this).serialize(), success : loginSuccess, error : loginError });
        return false;
    });
});

您还需要将data-ajax="false"作为属性添加到<form>标记,以便jQuery Mobile不会为您处理提交。

相关问题