Jquery mobile jQuery Mobile-加载外部HTML

Jquery mobile jQuery Mobile-加载外部HTML,jquery-mobile,Jquery Mobile,我正在将一些外部html加载到jquery移动应用程序的div中。一切都很好,但我正在努力使它更平滑一点 这是我的密码: $(document).bind('pagebeforecreate', function (event, ui) { if (event.target.id == 'pageViewOrder') { //get the page $.getJSON(root_url + '/orders/view/' + window.viewOr

我正在将一些外部html加载到jquery移动应用程序的div中。一切都很好,但我正在努力使它更平滑一点

这是我的密码:

$(document).bind('pagebeforecreate', function (event, ui) {
    if (event.target.id == 'pageViewOrder') {
        //get the page
        $.getJSON(root_url + '/orders/view/' + window.viewOrderReference + '/?callback=?', null, function (d) {
            $("#viewOrder_content").html(d.html).trigger("create");
            $.mobile.loading('hide');
        });
    }
所发生的事情是在ajax调用完成之前显示页面。有没有办法阻止jquery mobile在此调用完成之前继续显示页面?此时它显示页面,然后内容弹出

编辑:这是在单个页面中加载的

干杯,
Ben

停止显示过程很容易,您只需调用
event.preventDefault()
。 然后,问题是要确保一旦检索到内容,您将继续执行该过程。我实际上要做的是绑定到
pagechange
,检查您是否已经检索到数据,如果没有,则中断该过程,检索数据并重新开始。如果是,则按计划进行

var contentRetrieved = false; //will indicate wether the JSON call has already been executed
var contentToDisplay; //data from the JSON call

$(document).live('pagebeforechange', function (event, data) {
    if (( typeof data.toPage === "string" ) && ($.mobile.path.parseUrl(data.toPage).hash == '#pageViewOrder')) {
        if (contentRetrieved) {
           contentRetrieved = false; //content is already retrieved, we proceed with the pagechange
        } else {
           event.preventDefault(); //prevent further page change operations
           $.getJSON(root_url + '/orders/view/' + window.viewOrderReference + '/?callback=?', null, function (d) {
                contentToDisplay = {"html":d.html};
                contentRetrieved = true;
                $.mobile.changePage("#pageViewOrder");
            });
        }
    }
});


$(document).bind('pagebeforecreate', function (event, ui) {
    if (event.target.id == 'pageViewOrder') {
        $("#viewOrder_content").html(contentToDisplay.html).trigger("create");
        $.mobile.loading('hide');
    }
});​

感谢您的回复,我尝试了您的代码,但我得到以下错误:TypeError:contentToDisplay是未定义的名称问题。。。我做了一些提醒,出于某种原因,pagebeforecreate在pagebeforechange之前被调用。。。。hmm实际上,如果您的页面是第一个页面,则会发生这种情况,因为没有调用changepage。但是,如果您导航到该页面,应该不会有任何问题