0

我正在开发一个基于 jquery Mobile 的项目。我是这个领域的大人物,很抱歉这个愚蠢的问题。问题是——我有一个页面'Page1',我正在使用 post 方法从数据库中获取数据。成功后,我通过通知对话框向用户显示通知(没有取消和确定按钮)。现在我想要在另一个页面“page2”上显示这条成功消息,并且该消息应该存在长达 2 秒,然后自动消失。我努力了

function sendAddGuest(data, dialog) {

    $.post("/GuestsList/AddGuest", data, function (response) {  //using the post method
        //alert(JSON.stringify(response));
        $('.error').html("");
        hideLoading();

        if (response.result == 'success') { //if the process done


                $.mobile.changePage('/GuestsList/Index', { dataUrl: "/GuestsList/Index", reloadPage: false, changeHash: true });    //To another page "page2"

               // window.setTimeout('showToastMessage("Guest added successfully with window");',2000);  //i have tried this                
                setTimeout(function () { showToastMessage("Guest added successfully test2"); }, 100);   //and this also i want to show this message on other page "page2"
    }
}
4

1 回答 1

0

我也是从 Jquery Mobile 开始的,基于我正在使用的玩具项目,我建议如下:

  • 使用来自 jquerymobile 的弹出窗口而不是 showToast,然后您可以在 settimeout 函数中调用元素的 .close() 。

这是您为弹出窗口创建的 div(您将其放在第 2 页中):

<div data-role="popup" id="myPopup" class="ui-content" data-theme="e">
    <p>Guest added successfully</p>
</div>

这是您可以调用函数在新页面中打开一次的方式(使用 pageload 事件):

$('#myPopup').popup('open');

这就是调用函数关闭的方式(在同一个页面加载事件中):

window.setTimeout(function(){ $('#myPopup').popup('close'); }, 2000)

抱歉,我没有时间编写完整的示例,但我认为这是要走的路。

希望这可以帮助!:-)

于 2013-10-24T14:38:36.403 回答